diff --git a/flowspec/admin.py b/flowspec/admin.py
new file mode 100644
index 0000000000000000000000000000000000000000..13ece6dd17bb5e0cec1e838708f91f66e2082282
--- /dev/null
+++ b/flowspec/admin.py
@@ -0,0 +1,16 @@
+from django.contrib import admin
+from flowspy.flowspec.models import *
+
+admin.site.register(MatchAddress)
+admin.site.register(MatchPort)
+admin.site.register(MatchDscp)
+admin.site.register(MatchFragmentType)
+admin.site.register(MatchIcmpCode)
+admin.site.register(MatchIcmpType)
+admin.site.register(MatchPacketLength)
+admin.site.register(MatchProtocol)
+admin.site.register(MatchTcpFlag)
+admin.site.register(ThenAction)
+admin.site.register(ThenStatement)
+admin.site.register(MatchStatement)
+admin.site.register(Route)
diff --git a/flowspec/migrations/0001_initial.py b/flowspec/migrations/0001_initial.py
deleted file mode 100644
index 5a67e4659d7c2dcfc54d69576c7458e29afd4b6f..0000000000000000000000000000000000000000
--- a/flowspec/migrations/0001_initial.py
+++ /dev/null
@@ -1,335 +0,0 @@
-# encoding: utf-8
-import datetime
-from south.db import db
-from south.v2 import SchemaMigration
-from django.db import models
-
-class Migration(SchemaMigration):
-
- def forwards(self, orm):
-
- # Adding model 'MatchAddress'
- db.create_table(u'match_address', (
- ('destination', self.gf('django.db.models.fields.CharField')(max_length=255)),
- ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
- ))
- db.send_create_signal('flowspec', ['MatchAddress'])
-
- # Adding model 'MatchPort'
- db.create_table(u'match_port', (
- ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
- ('port', self.gf('django.db.models.fields.CharField')(max_length=24)),
- ))
- db.send_create_signal('flowspec', ['MatchPort'])
-
- # Adding model 'MatchDscp'
- db.create_table(u'match_dscp', (
- ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
- ('dscp', self.gf('django.db.models.fields.CharField')(max_length=24)),
- ))
- db.send_create_signal('flowspec', ['MatchDscp'])
-
- # Adding model 'MatchFragmentType'
- db.create_table(u'match_fragment_type', (
- ('fragmenttype', self.gf('django.db.models.fields.CharField')(max_length=20)),
- ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
- ))
- db.send_create_signal('flowspec', ['MatchFragmentType'])
-
- # Adding model 'MatchIcmpCode'
- db.create_table(u'match_icmp_code', (
- ('icmp_code', self.gf('django.db.models.fields.CharField')(max_length=64)),
- ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
- ))
- db.send_create_signal('flowspec', ['MatchIcmpCode'])
-
- # Adding model 'MatchIcmpType'
- db.create_table(u'match_icmp_type', (
- ('icmp_type', self.gf('django.db.models.fields.CharField')(max_length=64)),
- ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
- ))
- db.send_create_signal('flowspec', ['MatchIcmpType'])
-
- # Adding model 'MatchPacketLength'
- db.create_table(u'match_packet_length', (
- ('packet_length', self.gf('django.db.models.fields.IntegerField')()),
- ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
- ))
- db.send_create_signal('flowspec', ['MatchPacketLength'])
-
- # Adding model 'MatchProtocol'
- db.create_table(u'match_protocol', (
- ('protocol', self.gf('django.db.models.fields.CharField')(max_length=64)),
- ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
- ))
- db.send_create_signal('flowspec', ['MatchProtocol'])
-
- # Adding model 'MatchTcpFlag'
- db.create_table(u'match_tcp_flag', (
- ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
- ('tcp_flag', self.gf('django.db.models.fields.CharField')(max_length=255)),
- ))
- db.send_create_signal('flowspec', ['MatchTcpFlag'])
-
- # Adding model 'ThenAction'
- db.create_table(u'then_action', (
- ('action', self.gf('django.db.models.fields.CharField')(max_length=60)),
- ('action_value', self.gf('django.db.models.fields.CharField')(max_length=255, null=True, blank=True)),
- ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
- ))
- db.send_create_signal('flowspec', ['ThenAction'])
-
- # Adding model 'ThenStatement'
- db.create_table(u'then', (
- ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
- ))
- db.send_create_signal('flowspec', ['ThenStatement'])
-
- # Adding M2M table for field thenaction on 'ThenStatement'
- db.create_table(u'then_thenaction', (
- ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
- ('thenstatement', models.ForeignKey(orm['flowspec.thenstatement'], null=False)),
- ('thenaction', models.ForeignKey(orm['flowspec.thenaction'], null=False))
- ))
- db.create_unique(u'then_thenaction', ['thenstatement_id', 'thenaction_id'])
-
- # Adding model 'MatchStatement'
- db.create_table(u'match', (
- ('matchfragmenttype', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['flowspec.MatchFragmentType'], null=True, blank=True)),
- ('matchprotocol', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['flowspec.MatchProtocol'], null=True, blank=True)),
- ('matchicmptype', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['flowspec.MatchIcmpType'], null=True, blank=True)),
- ('matchSourcePort', self.gf('django.db.models.fields.related.ForeignKey')(blank=True, related_name='matchSourcePort', null=True, to=orm['flowspec.MatchPort'])),
- ('matchicmpcode', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['flowspec.MatchIcmpCode'], null=True, blank=True)),
- ('matchTcpFlag', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['flowspec.MatchTcpFlag'], null=True, blank=True)),
- ('matchDestination', self.gf('django.db.models.fields.related.ForeignKey')(blank=True, related_name='matchDestination', null=True, to=orm['flowspec.MatchAddress'])),
- ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
- ('matchpacketlength', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['flowspec.MatchPacketLength'], null=True, blank=True)),
- ))
- db.send_create_signal('flowspec', ['MatchStatement'])
-
- # Adding M2M table for field matchDestinationPort on 'MatchStatement'
- db.create_table(u'match_matchDestinationPort', (
- ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
- ('matchstatement', models.ForeignKey(orm['flowspec.matchstatement'], null=False)),
- ('matchport', models.ForeignKey(orm['flowspec.matchport'], null=False))
- ))
- db.create_unique(u'match_matchDestinationPort', ['matchstatement_id', 'matchport_id'])
-
- # Adding M2M table for field matchSource on 'MatchStatement'
- db.create_table(u'match_matchSource', (
- ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
- ('matchstatement', models.ForeignKey(orm['flowspec.matchstatement'], null=False)),
- ('matchaddress', models.ForeignKey(orm['flowspec.matchaddress'], null=False))
- ))
- db.create_unique(u'match_matchSource', ['matchstatement_id', 'matchaddress_id'])
-
- # Adding M2M table for field matchdscp on 'MatchStatement'
- db.create_table(u'match_matchdscp', (
- ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
- ('matchstatement', models.ForeignKey(orm['flowspec.matchstatement'], null=False)),
- ('matchdscp', models.ForeignKey(orm['flowspec.matchdscp'], null=False))
- ))
- db.create_unique(u'match_matchdscp', ['matchstatement_id', 'matchdscp_id'])
-
- # Adding M2M table for field matchport on 'MatchStatement'
- db.create_table(u'match_matchport', (
- ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
- ('matchstatement', models.ForeignKey(orm['flowspec.matchstatement'], null=False)),
- ('matchport', models.ForeignKey(orm['flowspec.matchport'], null=False))
- ))
- db.create_unique(u'match_matchport', ['matchstatement_id', 'matchport_id'])
-
- # Adding model 'Route'
- db.create_table(u'route', (
- ('then', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['flowspec.ThenStatement'])),
- ('last_updated', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, blank=True)),
- ('name', self.gf('django.db.models.fields.CharField')(max_length=128)),
- ('expires', self.gf('django.db.models.fields.DateTimeField')()),
- ('applier', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'])),
- ('filed', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)),
- ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
- ('match', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['flowspec.MatchStatement'])),
- ))
- db.send_create_signal('flowspec', ['Route'])
-
-
- def backwards(self, orm):
-
- # Deleting model 'MatchAddress'
- db.delete_table(u'match_address')
-
- # Deleting model 'MatchPort'
- db.delete_table(u'match_port')
-
- # Deleting model 'MatchDscp'
- db.delete_table(u'match_dscp')
-
- # Deleting model 'MatchFragmentType'
- db.delete_table(u'match_fragment_type')
-
- # Deleting model 'MatchIcmpCode'
- db.delete_table(u'match_icmp_code')
-
- # Deleting model 'MatchIcmpType'
- db.delete_table(u'match_icmp_type')
-
- # Deleting model 'MatchPacketLength'
- db.delete_table(u'match_packet_length')
-
- # Deleting model 'MatchProtocol'
- db.delete_table(u'match_protocol')
-
- # Deleting model 'MatchTcpFlag'
- db.delete_table(u'match_tcp_flag')
-
- # Deleting model 'ThenAction'
- db.delete_table(u'then_action')
-
- # Deleting model 'ThenStatement'
- db.delete_table(u'then')
-
- # Removing M2M table for field thenaction on 'ThenStatement'
- db.delete_table('then_thenaction')
-
- # Deleting model 'MatchStatement'
- db.delete_table(u'match')
-
- # Removing M2M table for field matchDestinationPort on 'MatchStatement'
- db.delete_table('match_matchDestinationPort')
-
- # Removing M2M table for field matchSource on 'MatchStatement'
- db.delete_table('match_matchSource')
-
- # Removing M2M table for field matchdscp on 'MatchStatement'
- db.delete_table('match_matchdscp')
-
- # Removing M2M table for field matchport on 'MatchStatement'
- db.delete_table('match_matchport')
-
- # Deleting model 'Route'
- db.delete_table(u'route')
-
-
- models = {
- 'auth.group': {
- 'Meta': {'object_name': 'Group'},
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
- 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
- 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
- },
- 'auth.permission': {
- 'Meta': {'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
- 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
- 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
- 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
- },
- 'auth.user': {
- 'Meta': {'object_name': 'User'},
- 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
- 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
- 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
- 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
- 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}),
- 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
- 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
- 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
- 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
- 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
- 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
- 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
- },
- 'contenttypes.contenttype': {
- 'Meta': {'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
- 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
- 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
- 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
- },
- 'flowspec.matchaddress': {
- 'Meta': {'object_name': 'MatchAddress', 'db_table': "u'match_address'"},
- 'destination': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
- },
- 'flowspec.matchdscp': {
- 'Meta': {'object_name': 'MatchDscp', 'db_table': "u'match_dscp'"},
- 'dscp': ('django.db.models.fields.CharField', [], {'max_length': '24'}),
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
- },
- 'flowspec.matchfragmenttype': {
- 'Meta': {'object_name': 'MatchFragmentType', 'db_table': "u'match_fragment_type'"},
- 'fragmenttype': ('django.db.models.fields.CharField', [], {'max_length': '20'}),
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
- },
- 'flowspec.matchicmpcode': {
- 'Meta': {'object_name': 'MatchIcmpCode', 'db_table': "u'match_icmp_code'"},
- 'icmp_code': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
- },
- 'flowspec.matchicmptype': {
- 'Meta': {'object_name': 'MatchIcmpType', 'db_table': "u'match_icmp_type'"},
- 'icmp_type': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
- },
- 'flowspec.matchpacketlength': {
- 'Meta': {'object_name': 'MatchPacketLength', 'db_table': "u'match_packet_length'"},
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
- 'packet_length': ('django.db.models.fields.IntegerField', [], {})
- },
- 'flowspec.matchport': {
- 'Meta': {'object_name': 'MatchPort', 'db_table': "u'match_port'"},
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
- 'port': ('django.db.models.fields.CharField', [], {'max_length': '24'})
- },
- 'flowspec.matchprotocol': {
- 'Meta': {'object_name': 'MatchProtocol', 'db_table': "u'match_protocol'"},
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
- 'protocol': ('django.db.models.fields.CharField', [], {'max_length': '64'})
- },
- 'flowspec.matchstatement': {
- 'Meta': {'object_name': 'MatchStatement', 'db_table': "u'match'"},
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
- 'matchDestination': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'matchDestination'", 'null': 'True', 'to': "orm['flowspec.MatchAddress']"}),
- 'matchDestinationPort': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'matchDestinationPort'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['flowspec.MatchPort']"}),
- 'matchSource': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'matchSource'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['flowspec.MatchAddress']"}),
- 'matchSourcePort': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'matchSourcePort'", 'null': 'True', 'to': "orm['flowspec.MatchPort']"}),
- 'matchTcpFlag': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['flowspec.MatchTcpFlag']", 'null': 'True', 'blank': 'True'}),
- 'matchdscp': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['flowspec.MatchDscp']", 'null': 'True', 'blank': 'True'}),
- 'matchfragmenttype': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['flowspec.MatchFragmentType']", 'null': 'True', 'blank': 'True'}),
- 'matchicmpcode': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['flowspec.MatchIcmpCode']", 'null': 'True', 'blank': 'True'}),
- 'matchicmptype': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['flowspec.MatchIcmpType']", 'null': 'True', 'blank': 'True'}),
- 'matchpacketlength': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['flowspec.MatchPacketLength']", 'null': 'True', 'blank': 'True'}),
- 'matchport': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['flowspec.MatchPort']", 'null': 'True', 'blank': 'True'}),
- 'matchprotocol': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['flowspec.MatchProtocol']", 'null': 'True', 'blank': 'True'})
- },
- 'flowspec.matchtcpflag': {
- 'Meta': {'object_name': 'MatchTcpFlag', 'db_table': "u'match_tcp_flag'"},
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
- 'tcp_flag': ('django.db.models.fields.CharField', [], {'max_length': '255'})
- },
- 'flowspec.route': {
- 'Meta': {'object_name': 'Route', 'db_table': "u'route'"},
- 'applier': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}),
- 'expires': ('django.db.models.fields.DateTimeField', [], {}),
- 'filed': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
- 'last_updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
- 'match': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['flowspec.MatchStatement']"}),
- 'name': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
- 'then': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['flowspec.ThenStatement']"})
- },
- 'flowspec.thenaction': {
- 'Meta': {'object_name': 'ThenAction', 'db_table': "u'then_action'"},
- 'action': ('django.db.models.fields.CharField', [], {'max_length': '60'}),
- 'action_value': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
- },
- 'flowspec.thenstatement': {
- 'Meta': {'object_name': 'ThenStatement', 'db_table': "u'then'"},
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
- 'thenaction': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['flowspec.ThenAction']", 'null': 'True', 'blank': 'True'})
- }
- }
-
- complete_apps = ['flowspec']
diff --git a/flowspec/migrations/__init__.py b/flowspec/migrations/__init__.py
deleted file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000
diff --git a/flowspec/models.py b/flowspec/models.py
index 60bad938ba21d0e7b7e3300e610ffb4a8a5f3ba8..1282553dabd0c79d9371ad29000ae64b53347619 100644
--- a/flowspec/models.py
+++ b/flowspec/models.py
@@ -1,6 +1,11 @@
from django.db import models
from django.contrib.auth.models import User
+import nxpy as np
+from ncclient import manager
+from ncclient.transport.errors import AuthenticationError, SSHError
+from lxml import etree as ET
+
FRAGMENT_CODES = (
("dont-fragment", "Don't fragment"),
("first-fragment", "First fragment"),
@@ -22,27 +27,37 @@ THEN_CHOICES = (
class MatchAddress(models.Model):
- destination = models.CharField(max_length=255)
+ address = models.CharField(max_length=255)
+ def __unicode__(self):
+ return self.address
class Meta:
db_table = u'match_address'
class MatchPort(models.Model):
port = models.CharField(max_length=24)
+ def __unicode__(self):
+ return self.port
class Meta:
db_table = u'match_port'
class MatchDscp(models.Model):
dscp = models.CharField(max_length=24)
+ def __unicode__(self):
+ return self.dscp
class Meta:
db_table = u'match_dscp'
class MatchFragmentType(models.Model):
fragmenttype = models.CharField(max_length=20, choices=FRAGMENT_CODES)
+ def __unicode__(self):
+ return self.fragmenttype
class Meta:
db_table = u'match_fragment_type'
class MatchIcmpCode(models.Model):
icmp_code = models.CharField(max_length=64)
+ def __unicode__(self):
+ return self.icmp_code
class Meta:
db_table = u'match_icmp_code'
@@ -58,17 +73,23 @@ class MatchPacketLength(models.Model):
class MatchProtocol(models.Model):
protocol = models.CharField(max_length=64)
+ def __unicode__(self):
+ return self.protocol
class Meta:
db_table = u'match_protocol'
class MatchTcpFlag(models.Model):
tcp_flag = models.CharField(max_length=255)
+ def __unicode__(self):
+ return self.tcp_flag
class Meta:
db_table = u'match_tcp_flag'
class ThenAction(models.Model):
action = models.CharField(max_length=60, choices=THEN_CHOICES)
action_value = models.CharField(max_length=255, blank=True, null=True)
+ def __unicode__(self):
+ return "%s %s" %(self.action, self.action_value)
class Meta:
db_table = u'then_action'
@@ -85,10 +106,10 @@ class MatchStatement(models.Model):
matchicmpcode = models.ForeignKey(MatchIcmpCode, blank=True, null=True)
matchicmptype = models.ForeignKey(MatchIcmpType, blank=True, null=True)
matchpacketlength = models.ForeignKey(MatchPacketLength, blank=True, null=True)
- matchport = models.ManyToManyField(MatchPort, blank=True, null=True)
+ matchport = models.ManyToManyField(MatchPort, blank=True, null=True, related_name="matchPort")
matchprotocol = models.ForeignKey(MatchProtocol, blank=True, null=True)
- matchSource = models.ManyToManyField(MatchAddress, blank=True, null=True, related_name="matchSource")
- matchSourcePort = models.ForeignKey(MatchPort, blank=True, null=True, related_name="matchSourcePort")
+ matchSource = models.ForeignKey(MatchAddress, blank=True, null=True, related_name="matchSource")
+ matchSourcePort = models.ManyToManyField(MatchPort, blank=True, null=True, related_name="matchSourcePort")
matchTcpFlag = models.ForeignKey(MatchTcpFlag, blank=True, null=True)
class Meta:
db_table = u'match'
@@ -101,5 +122,52 @@ class Route(models.Model):
filed = models.DateTimeField(auto_now_add=True)
last_updated = models.DateTimeField(auto_now=True)
expires = models.DateTimeField()
+ def __unicode__(self):
+ return self.name
+
class Meta:
- db_table = u'route'
\ No newline at end of file
+ db_table = u'route'
+
+ def save(self, *args, **kwargs):
+ # Begin translation to device xml configuration
+ device = np.Device()
+ flow = np.Flow()
+ route = np.Route()
+ flow.routes.append(route)
+ device.routing_options.append(flow)
+ route.name = self.name
+ match = self.match
+ if match.matchSource:
+ route.match['source'].append(match.matchSource.address)
+ if match.matchDestination:
+ route.match['destination'].append(match.matchDestination.address)
+ if match.matchprotocol:
+ route.match['protocol'].append(match.matchprotocol.protocol)
+ if match.matchport:
+ for port in match.matchport.all():
+ route.match['port'].append(port.port)
+ if match.matchDestinationPort:
+ for port in match.matchDestinationPort.all():
+ route.match['destination-port'].append(port.port)
+ if match.matchSourcePort:
+ for port in match.matchSourcePort.all():
+ route.match['source-port'].append(port.port)
+ if match.matchicmpcode:
+ route.match['icmp-code'].append(match.matchicmpcode.icmp_code)
+ if match.matchicmptype:
+ route.match['icmp-type'].append(match.matchicmptype.icmp_type)
+ if match.matchTcpFlag:
+ route.match['tcp-flags'].append(match.matchTcpFlag.tcp_flags)
+ if match.matchdscp:
+ for dscp in match.matchdscp.all():
+ route.match['dscp'].append(dscp.dscp)
+ if match.matchfragmenttype:
+ route.match['fragment'].append(match.matchfragmenttype.fragmenttype)
+ then = self.then
+ for thenaction in then.thenaction.all():
+ if thenaction.action_value:
+ route.then[thenaction.action] = thenaction.action_value
+ else:
+ route.then[thenaction.action] = True
+ print ET.tostring(device.export())
+ super(Route, self).save(*args, **kwargs)
\ No newline at end of file
diff --git a/urls.py b/urls.py
index fa52b55e3a7c2bf0fbd35a717dd6a1e2e8977dfc..32ffb38e0dc159d72b45407acd8ceeab13ac6c43 100644
--- a/urls.py
+++ b/urls.py
@@ -1,16 +1,16 @@
from django.conf.urls.defaults import *
# Uncomment the next two lines to enable the admin:
-# from django.contrib import admin
-# admin.autodiscover()
+from django.contrib import admin
+admin.autodiscover()
urlpatterns = patterns('',
# Example:
# (r'^flowspy/', include('flowspy.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
- # (r'^admin/doc/', include('django.contrib.admindocs.urls')),
+ (r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
- # (r'^admin/', include(admin.site.urls)),
+ (r'^admin/', include(admin.site.urls)),
)