add logger and fix wrong passing of argument in core module, cmd variable...

add logger and fix wrong passing of argument in core module, cmd variable resued which caused deletion of tunnel for creation itself: end to end traffic delivery tested for deidtect
parent 3a746059
...@@ -161,7 +161,7 @@ def deidtectAction(dic, start_response): ...@@ -161,7 +161,7 @@ def deidtectAction(dic, start_response):
tunid = dic.get('tunid',None) tunid = dic.get('tunid',None)
port = int(port) port = int(port)
vlanid = int(port) vlanid = int(vlanid)
tunid = int(tunid) tunid = int(tunid)
if site == "local": if site == "local":
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#the emulab openstack deployment follows *-mgmtNet notation for the management #the emulab openstack deployment follows *-mgmtNet notation for the management
#IP for the nodes #IP for the nodes
import logging as LOG
from eventlet import wsgi from eventlet import wsgi
from os import environ from os import environ
from time import sleep from time import sleep
...@@ -20,6 +22,8 @@ from routes import Mapper ...@@ -20,6 +22,8 @@ from routes import Mapper
import sys import sys
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
LOG.basicConfig(level=LOG.INFO)
def getNodeType(): def getNodeType():
d = {} d = {}
hostNameFull = socket.gethostname() hostNameFull = socket.gethostname()
...@@ -41,105 +45,106 @@ def sendError(start_response): ...@@ -41,105 +45,106 @@ def sendError(start_response):
COMPUTE_OVS_PATCH_PORT=1 COMPUTE_OVS_PATCH_PORT=1
def computeOFlowInstall(dic, start_response): def computeOFlowInstall(dic, start_response):
print "got computeOFlowInstall rq.." LOG.info("got computeOFlowInstall rq..")
cmd = dic.get('cmd',None) cmd = dic.get('cmd',None)
vlanid = dic.get('vlanid', None) vlanid = dic.get('vlanid', None)
tunid = dic.get('tunid',None) tunid = dic.get('tunid',None)
macadd = dic.get('mac',None) macadd = dic.get('mac',None)
print cmd LOG.info("cmd : %s", cmd)
print vlanid LOG.info("vlanid: %s ", vlanid)
print tunid LOG.info("tunid: %s" , tunid)
print macadd LOG.info("macadd: %s", macadd)
ovscmdlist = [] ovscmdlist = []
TAPMAC=macadd[3:] TAPMAC=macadd[3:]
TAPNAME='' TAPNAME=''
cmd = "ifconfig -a | grep %s | cut -d\' \' -f1" % TAPMAC ifcmd = "ifconfig -a | grep %s | cut -d\' \' -f1" % TAPMAC
p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE) p = Popen(ifcmd, shell=True, stdout=PIPE, stderr=PIPE)
out, err = p.communicate() out, err = p.communicate()
TAPNAME=out.rstrip() TAPNAME=out.rstrip()
print "TAPNAME: %s" % TAPNAME LOG.info("TAPNAME: %s", TAPNAME)
OVSPORTNAME='qvo%s' % TAPNAME[3:] OVSPORTNAME='qvo%s' % TAPNAME[3:]
LOG.info("OVSPORTNAME: %s", OVSPORTNAME)
VMINPUTCHAINFALLBACK="neutron-openvswi-sg-fallback" VMINPUTCHAINFALLBACK="neutron-openvswi-sg-fallback"
VMCHAININPUT="neutron-openvswi-i%s" %TAPNAME[3:-1] VMCHAININPUT="neutron-openvswi-i%s" %TAPNAME[3:-1]
cmd = "sudo ovs-ofctl show br-int | grep %s | cut -d\'(\' -f 1" % OVSPORTNAME ifcmd = "sudo ovs-ofctl show br-int | grep %s | cut -d\'(\' -f 1" % OVSPORTNAME
#print cmd #print cmd
p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE) p = Popen(ifcmd, shell=True, stdout=PIPE, stderr=PIPE)
out, err = p.communicate() out, err = p.communicate()
print out, err LOG.info("%s, %s", out, err)
OVSPORTNUMBER=out.rstrip().replace(' ','') OVSPORTNUMBER=out.rstrip().replace(' ','')
print "OVSBRIDGE: %s @ %s" % (OVSPORTNAME, OVSPORTNUMBER) LOG.info("OVSBRIDGE: %s @ %s" ,OVSPORTNAME, OVSPORTNUMBER)
if cmd == "add": if cmd == "add":
computetunflow = 'sudo ovs-ofctl add-flow br-tun priority=3,tun_id=%d,actions=mod_vlan_vid:%d,output:%d' \ computetunflow = 'sudo ovs-ofctl add-flow br-tun priority=3,tun_id=%d,actions=mod_vlan_vid:%d,output:%d' \
% (int(tunid), int(vlanid), COMPUTE_OVS_PATCH_PORT) % (int(tunid), int(vlanid), COMPUTE_OVS_PATCH_PORT)
print computetunflow LOG.info("%s", computetunflow)
ovscmdlist.append(computetunflow) ovscmdlist.append(computetunflow)
computeintflow = 'sudo ovs-ofctl add-flow br-int priority=3,dl_vlan=%d,actions=strip_vlan,output:%d' \ computeintflow = 'sudo ovs-ofctl add-flow br-int priority=3,dl_vlan=%d,actions=strip_vlan,output:%d' \
% (int(vlanid), int(OVSPORTNUMBER)) % (int(vlanid), int(OVSPORTNUMBER))
print computeintflow LOG.info("%s", computeintflow )
ovscmdlist.append(computeintflow) ovscmdlist.append(computeintflow)
print "install drop rule for outgoing traffic" LOG.info("install drop rule for outgoing traffic")
computedropoutflow = 'sudo ovs-ofctl add-flow br-int priority=3,in_port=%d,actions=' \ computedropoutflow = 'sudo ovs-ofctl add-flow br-int priority=3,in_port=%d,actions=' \
% (int(OVSPORTNUMBER)) % (int(OVSPORTNUMBER))
print computedropoutflow LOG.info("%s", computedropoutflow)
ovscmdlist.append(computedropoutflow) ovscmdlist.append(computedropoutflow)
print "Reconfiguring iptables for ids vm traffic" LOG.info("Reconfiguring iptables for ids vm traffic")
iptable_allowall= "sudo iptables -A %s -p all -j RETURN" % VMCHAININPUT iptable_allowall= "sudo iptables -A %s -p all -j RETURN" % VMCHAININPUT
print iptable_allowall LOG.info("%s", iptable_allowall)
ovscmdlist.append(iptable_allowall) ovscmdlist.append(iptable_allowall)
#rearrange iptable chain in cmd #rearrange iptable chain in cmd
iptable_del_fallback = "sudo iptables -D %s -p all -j %s" % (VMCHAININPUT, VMINPUTCHAINFALLBACK) iptable_del_fallback = "sudo iptables -D %s -p all -j %s" % (VMCHAININPUT, VMINPUTCHAINFALLBACK)
print iptable_del_fallback LOG.info("%s", iptable_del_fallback)
ovscmdlist.append(iptable_del_fallback) ovscmdlist.append(iptable_del_fallback)
iptable_add_fallback = "sudo iptables -A %s -p all -j %s" % (VMCHAININPUT, VMINPUTCHAINFALLBACK) iptable_add_fallback = "sudo iptables -A %s -p all -j %s" % (VMCHAININPUT, VMINPUTCHAINFALLBACK)
print iptable_add_fallback LOG.info("%s", iptable_add_fallback)
ovscmdlist.append(iptable_add_fallback) ovscmdlist.append(iptable_add_fallback)
else: else:
computetunflow = 'sudo ovs-ofctl del-flows br-tun tun_id=%d' \ computetunflow = 'sudo ovs-ofctl del-flows br-tun tun_id=%d' \
% (int(tunid)) % (int(tunid))
print computetunflow LOG.info("%s", computetunflow)
ovscmdlist.append(computetunflow) ovscmdlist.append(computetunflow)
computeintflow = 'sudo ovs-ofctl del-flows br-int dl_vlan=%d' \ computeintflow = 'sudo ovs-ofctl del-flows br-int dl_vlan=%d' \
% (int(vlanid)) % (int(vlanid))
print computeintflow LOG.info("%s", computeintflow)
ovscmdlist.append(computeintflow) ovscmdlist.append(computeintflow)
computedropoutflow = 'sudo ovs-ofctl del-flows br-int in_port=%d' \ computedropoutflow = 'sudo ovs-ofctl del-flows br-int in_port=%d' \
% (int(OVSPORTNUMBER)) % (int(OVSPORTNUMBER))
print computedropoutflow LOG.info("%s", computedropoutflow)
ovscmdlist.append(computedropoutflow) ovscmdlist.append(computedropoutflow)
for cmd in ovscmdlist: for cmd in ovscmdlist:
p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE) p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
out, err = p.communicate() out, err = p.communicate()
print out,err LOG.info("%s, %s", out,err)
return sendOK(start_response); return sendOK(start_response);
NET_OVS_BR_INT_PORT=2 NET_OVS_BR_INT_PORT=2
NET_OVS_PATCH_PORT=2 NET_OVS_PATCH_PORT=2
def networkOFlowInstall(dic, start_response): def networkOFlowInstall(dic, start_response):
print "got networkOFlowInstall rq.." LOG.info("got networkOFlowInstall rq..")
cmd = dic.get('cmd',None) cmd = dic.get('cmd',None)
vlanid = dic.get('vlanid', None) vlanid = dic.get('vlanid', None)
tunname = dic.get('tunname',None) tunname = dic.get('tunname',None)
tunid = dic.get('tunid',None) tunid = dic.get('tunid',None)
print cmd LOG.info("cmd: %s", cmd)
print vlanid LOG.info("vlan: %s", vlanid)
print tunname LOG.info("tunname: %s", tunname)
print tunid LOG.info("tunid: %s", tunid)
ovscmdlist = [] ovscmdlist = []
...@@ -152,45 +157,45 @@ def networkOFlowInstall(dic, start_response): ...@@ -152,45 +157,45 @@ def networkOFlowInstall(dic, start_response):
networkexflow='sudo ovs-ofctl add-flow br-ex priority=3,dl_vlan=%d,actions=output:%d' \ networkexflow='sudo ovs-ofctl add-flow br-ex priority=3,dl_vlan=%d,actions=output:%d' \
% (int(vlanid), NET_OVS_BR_INT_PORT); % (int(vlanid), NET_OVS_BR_INT_PORT);
print networkexflow LOG.info("%s", networkexflow)
ovscmdlist.append(networkexflow) ovscmdlist.append(networkexflow)
networkexpatch='sudo ovs-ofctl add-flow br-int priority=3,dl_vlan=%d,actions=output:%d' \ networkexpatch='sudo ovs-ofctl add-flow br-int priority=3,dl_vlan=%d,actions=output:%d' \
% (int(vlanid), \ % (int(vlanid), \
NET_OVS_PATCH_PORT); NET_OVS_PATCH_PORT);
print networkexpatch LOG.info("%s", networkexpatch)
ovscmdlist.append(networkexpatch) ovscmdlist.append(networkexpatch)
networkexgre='sudo ovs-ofctl add-flow br-tun priority=3,dl_vlan=%d,actions=strip_vlan,set_tunnel:%d,output:%d' \ networkexgre='sudo ovs-ofctl add-flow br-tun priority=3,dl_vlan=%d,actions=strip_vlan,set_tunnel:%d,output:%d' \
% (int(vlanid), int(tunid), int(greport)) % (int(vlanid), int(tunid), int(greport))
print networkexgre LOG.info("%s", networkexgre)
ovscmdlist.append(networkexgre) ovscmdlist.append(networkexgre)
else: else:
networkexflow='sudo ovs-ofctl del-flows br-ex dl_vlan=%d' \ networkexflow='sudo ovs-ofctl del-flows br-ex dl_vlan=%d' \
% (int(vlanid)); % (int(vlanid));
print networkexflow LOG.info("%s", networkexflow)
ovscmdlist.append(networkexflow) ovscmdlist.append(networkexflow)
networkexpatch='sudo ovs-ofctl del-flows br-int dl_vlan=%d' \ networkexpatch='sudo ovs-ofctl del-flows br-int dl_vlan=%d' \
% (int(vlanid)); % (int(vlanid));
print networkexpatch LOG.info("%s", networkexpatch)
ovscmdlist.append(networkexpatch) ovscmdlist.append(networkexpatch)
networkexgre='sudo ovs-ofctl del-flows br-tun dl_vlan=%d' \ networkexgre='sudo ovs-ofctl del-flows br-tun dl_vlan=%d' \
% (int(vlanid)) % (int(vlanid))
print networkexgre LOG.info("%s", networkexgre)
ovscmdlist.append(networkexgre) ovscmdlist.append(networkexgre)
for cmd in ovscmdlist: for cmd in ovscmdlist:
p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE) p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
out, err = p.communicate() out, err = p.communicate()
print out,err LOG.info("%s, %s", out,err)
return sendOK(start_response); return sendOK(start_response);
...@@ -202,7 +207,7 @@ def networkapp(environ, start_response): ...@@ -202,7 +207,7 @@ def networkapp(environ, start_response):
if result is not None: if result is not None:
print result print result
print "called.. %s" % result['action'] LOG.info("called.. %s", result['action'])
return globals()[result['action']](result, start_response) return globals()[result['action']](result, start_response)
return sendError(start_response) return sendError(start_response)
......
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