added wancontroller infrastructure for remote delivery of tunnel traffic -...

added wancontroller infrastructure for remote delivery of tunnel traffic - currently uses enterprise(EMULAB node) change it to renterprise later
parent e675e09a
"""
This module creates the gre tunnels between
1. remote enterprise and ext (port 1)
2. ext and OpenStack network node (port 2)
TODO: Add the network node gre endpoint for remote access
tunnel for the vlan and also creates .
use port: 100 for the wsgi port interface
==========================
sudo ovs-vsctl del-br wan-br
sudo ovs-vsctl add-br wan-br
sudo ovs-vsctl add-port wan-br deid0 -- set interface deid0 type=gre \
options:remote_ip=renterprise-deidtect-localtap options:local_ip=ext
sudo ovs-vsctl add-port wan-br deid1 -- set interface deid1 type=gre \
options:remote_ip=network.deidtect-localtap options:local_ip=ext
"""
from eventlet import wsgi
from os import environ
from time import sleep
import cmd, socket
import eventlet
from eventlet import wsgi
from cgi import parse_qs, escape
import thread
from routes import Mapper
import sys
from subprocess import Popen, PIPE
def getNodeIP():
d = {}
d['enterprise'] = socket.gethostbyname('enterprise.DEIDtect-LocalTap.TCloud.emulab.net')
d['network'] = socket.gethostbyname('network.DEIDtect-LocalTap.TCloud.emulab.net')
d['wan'] = socket.gethostbyname('ext.DEIDtect-LocalTap.TCloud.emulab.net')
return d
print getNodeIP();
def setupOVS(nodeIP):
ovscmdlist = []
ovscmdlist.append("sudo ovs-vsctl del-br wan-br 2>/dev/null")
ovscmdlist.append("sudo ovs-vsctl add-br wan-br")
ovscmdlist.append('sudo ovs-vsctl add-port wan-br deid0 -- set interface \
deid0 type=gre options:remote_ip=%s options:local_ip=%s' \
%(nodeIP['enterprise'], nodeIP['wan']))
ovscmdlist.append('sudo ovs-vsctl add-port wan-br deid1 -- set interface \
deid1 type=gre options:remote_ip=%s options:local_ip=%s' \
%(nodeIP['network'], nodeIP['wan']))
for cmd in ovscmdlist:
print cmd
p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
out, err = p.communicate()
print out,err
def sendOK(start_response):
start_response("200 OK", [('Content-type', 'text/plain')])
return ['OK']
def sendError(start_response):
start_response("404 Not Found", [('Content-type',
'text/plain')])
return ['Page not found']
def wanActions(dic, start_response):
print "got wanAction request..."
cmd = dic.get('cmd',None)
vlanid = dic.get('vlanid',None)
print cmd,vlanid
if cmd == "add":
tunflow = 'sudo ovs-ofctl add-flow wan-br priority=3,dl_vlan=%d,actions=output:2' \
% (int(vlanid))
else:
tunflow = 'sudo ovs-ofctl del-flows wan-br dl_vlan=%d' % (int(vlanid))
print tunflow
p = Popen(tunflow, shell=True, stdout=PIPE, stderr=PIPE)
out, err = p.communicate()
print out, err
return sendOK(start_response);
def networkapp(environ, start_response):
cur_path = environ['PATH_INFO']
print mapper
print cur_path
result = mapper.match(cur_path)
if result is not None:
print result
print "called.. %s" % result['action']
return globals()[result['action']](result, start_response)
return sendError(start_response)
def start_wan_server(port, hostip):
global mapper
mapper = Mapper()
route_name = 'wanhelper'
print "Server : WAN Helper DEIDtect for Network Started.."
uri = '/wanhelper/{cmd}/{vlanid}'
mapper.connect(route_name, uri, controller="home",
action='wanActions',
conditions=dict(method=['GET']))
wsgi.server(eventlet.listen((hostip, port)), networkapp)
print "Server : WAN Helper DEIDtect for Network Stopped"
if __name__ == '__main__':
nodeIP = getNodeIP();
setupOVS(nodeIP);
start_wan_server(100,nodeIP['wan']);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment