Skip to content

Commit

Permalink
- fixed create flow route
Browse files Browse the repository at this point in the history
  • Loading branch information
cklewar committed Apr 9, 2018
1 parent f7ccae8 commit fa2e99e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 20 deletions.
29 changes: 16 additions & 13 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import datetime
import yaml
import re
import pprint

from jnpr.junos.utils.config import Config
from jnpr.junos import Device
Expand All @@ -46,9 +45,9 @@ def __init__(self):

def addNewFlowRoute(self, flowRouteData=None):

# env = Environment(autoescape=False,
#env = Environment(autoescape=False,
# loader=FileSystemLoader('./template'), trim_blocks=False, lstrip_blocks=False)
# template = env.get_template('set-flow-route.conf')
#template = env.get_template('set-flow-route.conf')

with Device(host=self.routers[0]['rt1']['ip'], user=self.dev_user, password=self.dev_pw) as dev:

Expand All @@ -64,11 +63,11 @@ def addNewFlowRoute(self, flowRouteData=None):
except ConfigLoadError as cle:
return False, cle.message

self.flow_config[flowRouteData['flowRouteName']] = {'dstPrefix': flowRouteData['dstPrefix'],
'srcPrefix': flowRouteData['srcPrefix'],
'protocol': flowRouteData['protocol'],
'dstPort': flowRouteData['dstPort'],
'srcPort': flowRouteData['srcPort'],
self.flow_config[flowRouteData['flowRouteName']] = {'dstPrefix': flowRouteData['dstPrefix'] if 'dstPrefix' in flowRouteData else None,
'srcPrefix': flowRouteData['srcPrefix'] if 'srcPrefix' in flowRouteData else None,
'protocol': flowRouteData['protocol'] if 'protocol' in flowRouteData else None,
'dstPort': flowRouteData['dstPort'] if 'dstPort' in flowRouteData else None,
'srcPort': flowRouteData['srcPort'] if 'srcPort' in flowRouteData else None,
'action': flowRouteData['action']}
return True, 'Successfully added new flow route'

Expand Down Expand Up @@ -110,6 +109,7 @@ def delFlowRoute(self, flowRouteData=None):
def getActiveFlowRoutes(self):

t = datetime.datetime.strptime(self.age_out_interval, "%H:%M:%S")
self.flow_active = dict()

for router in self.routers:

Expand Down Expand Up @@ -301,11 +301,14 @@ def loadFlowRouteConfig(self):
else:
_action[key] = {'value': None}

self.flow_config[route['name']] = {'dstPrefix': route['match']['destination'],
'srcPrefix': route['match']['source'],
'protocol': route['match']['protocol'],
'dstPort': route['match']['destination-port'],
'srcPort': route['match']['source-port'], 'action': _action}
print route

self.flow_config[route['name']] = {'dstPrefix': route['match']['destination'] if 'destination' in route['match'] else '*',
'srcPrefix': route['match']['source'] if 'source' in route['match'] else '*',
'protocol': route['match']['protocol'] if 'protocol' in route['match'] else '*',
'dstPort': route['match']['destination-port'] if 'destination-port' in route['match'] else '*',
'srcPort': route['match']['source-port'] if 'source-port' in route['match'] else '*',
'action': _action}
return True, self.flow_config

else:
Expand Down
2 changes: 2 additions & 0 deletions template/set-flow-route.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ routing-options {
flow {
route {{ flowRouteName }} {
match {
{%- if dstPrefix is defined and dstPrefix !=None %}
destination {{dstPrefix}};
{%- endif %}
{%- if dstPort is defined and dstPort !=None %}
destination-port {{ dstPort }};
{%- endif %}
Expand Down
19 changes: 13 additions & 6 deletions ui/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,20 @@ function flowRouteAddNewConfigEventHandler(){
var data = new Object();

data.flowRouteName = $('#inputFlowRouteName').val();
data.srcPrefix = $('#inputSrcPrefix').val();
data.srcPort = $('#inputSrcPort').val();
data.dstPrefix = $('#inputDstPrefix').val();
data.dstPort = $('#inputDstPort').val();
data.protocol = $('#selectProtocol').val();
data.action = $('#selectAction').val();

if ($('#inputSrcPrefix').val()){
data.srcPrefix = $('#inputSrcPrefix').val();
} else if ($('#inputSrcPort').val()){
data.srcPort = $('#inputSrcPort').val();
} else if ($('#inputDstPrefix').val()){
data.dstPrefix = $('#inputDstPrefix').val();
} else if ($('#inputDstPort').val()) {
data.dstPort = $('#inputDstPort').val();
} else if ($('#selectProtocol').val()) {
data.protocol = $('#selectProtocol').val();
}

data.action = $('#selectAction').val();
addNewFlowRouteConfig(data);
});
}
Expand Down
2 changes: 1 addition & 1 deletion utils/testdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

testdata = dict()
start = 1
stop = 2001
stop = 101
step = 1
protocol = ['tcp', 'udp']
action = ['accept', 'discard', 'sample']
Expand Down

0 comments on commit fa2e99e

Please sign in to comment.