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):
tunid = dic.get('tunid',None)
port = int(port)
vlanid = int(port)
vlanid = int(vlanid)
tunid = int(tunid)
if site == "local":
......
......@@ -8,6 +8,8 @@
#the emulab openstack deployment follows *-mgmtNet notation for the management
#IP for the nodes
import logging as LOG
from eventlet import wsgi
from os import environ
from time import sleep
......@@ -20,6 +22,8 @@ from routes import Mapper
import sys
from subprocess import Popen, PIPE
LOG.basicConfig(level=LOG.INFO)
def getNodeType():
d = {}
hostNameFull = socket.gethostname()
......@@ -41,105 +45,106 @@ def sendError(start_response):
COMPUTE_OVS_PATCH_PORT=1
def computeOFlowInstall(dic, start_response):
print "got computeOFlowInstall rq.."
LOG.info("got computeOFlowInstall rq..")
cmd = dic.get('cmd',None)
vlanid = dic.get('vlanid', None)
tunid = dic.get('tunid',None)
macadd = dic.get('mac',None)
print cmd
print vlanid
print tunid
print macadd
LOG.info("cmd : %s", cmd)
LOG.info("vlanid: %s ", vlanid)
LOG.info("tunid: %s" , tunid)
LOG.info("macadd: %s", macadd)
ovscmdlist = []
TAPMAC=macadd[3:]
TAPNAME=''
cmd = "ifconfig -a | grep %s | cut -d\' \' -f1" % TAPMAC
p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
ifcmd = "ifconfig -a | grep %s | cut -d\' \' -f1" % TAPMAC
p = Popen(ifcmd, shell=True, stdout=PIPE, stderr=PIPE)
out, err = p.communicate()
TAPNAME=out.rstrip()
print "TAPNAME: %s" % TAPNAME
LOG.info("TAPNAME: %s", TAPNAME)
OVSPORTNAME='qvo%s' % TAPNAME[3:]
LOG.info("OVSPORTNAME: %s", OVSPORTNAME)
VMINPUTCHAINFALLBACK="neutron-openvswi-sg-fallback"
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
p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
p = Popen(ifcmd, shell=True, stdout=PIPE, stderr=PIPE)
out, err = p.communicate()
print out, err
LOG.info("%s, %s", out, err)
OVSPORTNUMBER=out.rstrip().replace(' ','')
print "OVSBRIDGE: %s @ %s" % (OVSPORTNAME, OVSPORTNUMBER)
LOG.info("OVSBRIDGE: %s @ %s" ,OVSPORTNAME, OVSPORTNUMBER)
if cmd == "add":
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)
print computetunflow
LOG.info("%s", computetunflow)
ovscmdlist.append(computetunflow)
computeintflow = 'sudo ovs-ofctl add-flow br-int priority=3,dl_vlan=%d,actions=strip_vlan,output:%d' \
% (int(vlanid), int(OVSPORTNUMBER))
print computeintflow
LOG.info("%s", 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=' \
% (int(OVSPORTNUMBER))
print computedropoutflow
LOG.info("%s", 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
print iptable_allowall
LOG.info("%s", iptable_allowall)
ovscmdlist.append(iptable_allowall)
#rearrange iptable chain in cmd
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)
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)
else:
computetunflow = 'sudo ovs-ofctl del-flows br-tun tun_id=%d' \
% (int(tunid))
print computetunflow
LOG.info("%s", computetunflow)
ovscmdlist.append(computetunflow)
computeintflow = 'sudo ovs-ofctl del-flows br-int dl_vlan=%d' \
% (int(vlanid))
print computeintflow
LOG.info("%s", computeintflow)
ovscmdlist.append(computeintflow)
computedropoutflow = 'sudo ovs-ofctl del-flows br-int in_port=%d' \
% (int(OVSPORTNUMBER))
print computedropoutflow
LOG.info("%s", computedropoutflow)
ovscmdlist.append(computedropoutflow)
for cmd in ovscmdlist:
p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
out, err = p.communicate()
print out,err
LOG.info("%s, %s", out,err)
return sendOK(start_response);
NET_OVS_BR_INT_PORT=2
NET_OVS_PATCH_PORT=2
def networkOFlowInstall(dic, start_response):
print "got networkOFlowInstall rq.."
LOG.info("got networkOFlowInstall rq..")
cmd = dic.get('cmd',None)
vlanid = dic.get('vlanid', None)
tunname = dic.get('tunname',None)
tunid = dic.get('tunid',None)
print cmd
print vlanid
print tunname
print tunid
LOG.info("cmd: %s", cmd)
LOG.info("vlan: %s", vlanid)
LOG.info("tunname: %s", tunname)
LOG.info("tunid: %s", tunid)
ovscmdlist = []
......@@ -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' \
% (int(vlanid), NET_OVS_BR_INT_PORT);
print networkexflow
LOG.info("%s", networkexflow)
ovscmdlist.append(networkexflow)
networkexpatch='sudo ovs-ofctl add-flow br-int priority=3,dl_vlan=%d,actions=output:%d' \
% (int(vlanid), \
NET_OVS_PATCH_PORT);
print networkexpatch
LOG.info("%s", 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' \
% (int(vlanid), int(tunid), int(greport))
print networkexgre
LOG.info("%s", networkexgre)
ovscmdlist.append(networkexgre)
else:
networkexflow='sudo ovs-ofctl del-flows br-ex dl_vlan=%d' \
% (int(vlanid));
print networkexflow
LOG.info("%s", networkexflow)
ovscmdlist.append(networkexflow)
networkexpatch='sudo ovs-ofctl del-flows br-int dl_vlan=%d' \
% (int(vlanid));
print networkexpatch
LOG.info("%s", networkexpatch)
ovscmdlist.append(networkexpatch)
networkexgre='sudo ovs-ofctl del-flows br-tun dl_vlan=%d' \
% (int(vlanid))
print networkexgre
LOG.info("%s", networkexgre)
ovscmdlist.append(networkexgre)
for cmd in ovscmdlist:
p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
out, err = p.communicate()
print out,err
LOG.info("%s, %s", out,err)
return sendOK(start_response);
......@@ -202,7 +207,7 @@ def networkapp(environ, start_response):
if result is not None:
print result
print "called.. %s" % result['action']
LOG.info("called.. %s", result['action'])
return globals()[result['action']](result, 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