Statistics
| Branch: | Tag: | Revision:

root / flowspec / models.py @ a3af8464

History | View | Annotate | Download (3.7 kB)

1
from django.db import models
2
from django.contrib.auth.models import User
3

    
4
FRAGMENT_CODES = (
5
    ("dont-fragment", "Don't fragment"),
6
    ("first-fragment", "First fragment"),
7
    ("is-fragment", "Is fragment"),
8
    ("last-fragment", "Last fragment"),
9
    ("not-a-fragment", "Not a fragment")
10
)
11

    
12
THEN_CHOICES = (
13
    ("accept", "Accept"),
14
    ("discard", "Discard"),
15
    ("community", "Community"),
16
    ("next-term", "Next term"),
17
    ("routing-instance", "Routing Instance"),
18
    ("rate-limit", "Rate limit"),
19
    ("sample", "Sample")                
20
)
21

    
22

    
23
    
24
class MatchAddress(models.Model):
25
    destination = models.CharField(max_length=255)
26
    class Meta:
27
        db_table = u'match_address'
28

    
29
class MatchPort(models.Model):
30
    port = models.CharField(max_length=24)
31
    class Meta:
32
        db_table = u'match_port'    
33

    
34
class MatchDscp(models.Model):
35
    dscp = models.CharField(max_length=24)
36
    class Meta:
37
        db_table = u'match_dscp'
38

    
39
class MatchFragmentType(models.Model):
40
    fragmenttype = models.CharField(max_length=20, choices=FRAGMENT_CODES)
41
    class Meta:
42
        db_table = u'match_fragment_type'
43
    
44
class MatchIcmpCode(models.Model):
45
    icmp_code = models.CharField(max_length=64)
46
    class Meta:
47
        db_table = u'match_icmp_code'    
48

    
49
class MatchIcmpType(models.Model):
50
    icmp_type = models.CharField(max_length=64)
51
    class Meta:
52
        db_table = u'match_icmp_type'    
53

    
54
class MatchPacketLength(models.Model):
55
    packet_length = models.IntegerField()
56
    class Meta:
57
        db_table = u'match_packet_length'    
58

    
59
class MatchProtocol(models.Model):
60
    protocol = models.CharField(max_length=64)
61
    class Meta:
62
        db_table = u'match_protocol'    
63

    
64
class MatchTcpFlag(models.Model):
65
    tcp_flag = models.CharField(max_length=255)
66
    class Meta:
67
        db_table = u'match_tcp_flag'    
68
    
69
class ThenAction(models.Model):
70
    action = models.CharField(max_length=60, choices=THEN_CHOICES)
71
    action_value = models.CharField(max_length=255, blank=True, null=True)
72
    class Meta:
73
        db_table = u'then_action'
74

    
75
class ThenStatement(models.Model):
76
    thenaction = models.ManyToManyField(ThenAction, blank=True, null=True)
77
    class Meta:
78
        db_table = u'then'    
79

    
80
class MatchStatement(models.Model):
81
    matchDestination = models.ForeignKey(MatchAddress, blank=True, null=True, related_name="matchDestination")
82
    matchDestinationPort = models.ManyToManyField(MatchPort, blank=True, null=True, related_name="matchDestinationPort")
83
    matchdscp = models.ManyToManyField(MatchDscp, blank=True, null=True)
84
    matchfragmenttype = models.ForeignKey(MatchFragmentType, blank=True, null=True)
85
    matchicmpcode = models.ForeignKey(MatchIcmpCode, blank=True, null=True)
86
    matchicmptype = models.ForeignKey(MatchIcmpType, blank=True, null=True)
87
    matchpacketlength = models.ForeignKey(MatchPacketLength, blank=True, null=True)
88
    matchport = models.ManyToManyField(MatchPort, blank=True, null=True)
89
    matchprotocol = models.ForeignKey(MatchProtocol, blank=True, null=True)
90
    matchSource = models.ManyToManyField(MatchAddress, blank=True, null=True, related_name="matchSource")
91
    matchSourcePort = models.ForeignKey(MatchPort, blank=True, null=True, related_name="matchSourcePort")
92
    matchTcpFlag = models.ForeignKey(MatchTcpFlag, blank=True, null=True)
93
    class Meta:
94
        db_table = u'match'
95

    
96
class Route(models.Model):
97
    name = models.CharField(max_length=128)
98
    applier = models.ForeignKey(User)
99
    match = models.ForeignKey(MatchStatement)
100
    then = models.ForeignKey(ThenStatement)
101
    filed = models.DateTimeField(auto_now_add=True)
102
    last_updated = models.DateTimeField(auto_now=True)
103
    expires = models.DateTimeField()
104
    class Meta:
105
        db_table = u'route'