update openflow code before migration
authorJulien Tribino <julien.tribino@inria.fr>
Thu, 14 Nov 2013 14:09:29 +0000 (15:09 +0100)
committerJulien Tribino <julien.tribino@inria.fr>
Thu, 14 Nov 2013 14:09:29 +0000 (15:09 +0100)
examples/openvswitch/ovs_ping_exp.py
src/nepi/resources/planetlab/openvswitch/ovs.py
src/nepi/resources/planetlab/openvswitch/ovsport.py
src/nepi/resources/planetlab/openvswitch/tunnel.py

index 77ee916..b73e8ae 100644 (file)
 
 
 from nepi.execution.ec import ExperimentController
+import os, time
 
-def add_node(ec, host, user):
+def add_node(ec, host, user, pl_user, pl_password):
     node = ec.register_resource("PlanetlabNode")
     ec.set(node, "hostname", host)
     ec.set(node, "username", user)
+    if pl_user:
+        ec.set(node, "pluser", pl_user)
+    if pl_password:
+        ec.set(node, "plpassword", pl_password)
     ec.set(node, "cleanHome", True)
     ec.set(node, "cleanProcesses", True)
+
     return node
 
 def add_ovs(ec, bridge_name, virtual_ip_pref, controller_ip, controller_port, node):
@@ -62,7 +68,7 @@ def add_tap(ec, ip4, prefix4, pointopoint, node):
     return tap
 
 def add_tunnel(ec, port0, tap):
-    tunnel = ec.register_resource("Tunnel")
+    tunnel = ec.register_resource("OVSTunnel")
     ec.register_connection(port0, tunnel)
     ec.register_connection(tunnel, tap)
     return tunnel
@@ -79,12 +85,15 @@ ec = ExperimentController(exp_id = "one")
 switch1 = "planetlab2.virtues.fi"
 switch2 = "planetlab2.upc.es"
 host1 = "planetlab2.ionio.gr"
-host2 = "planetlab2.cs.aueb.gr"
+host2 = "planetlab2.diku.dk"
 
 slicename = "inria_nepi"
 
-s1_node = add_node(ec, switch1, slicename)
-s2_node = add_node(ec, switch2, slicename)
+pl_user = os.environ.get("PL_USER")
+pl_password =  os.environ.get("PL_PASS")
+
+s1_node = add_node(ec, switch1, slicename, pl_user, pl_password)
+s2_node = add_node(ec, switch2, slicename, pl_user, pl_password)
 
 # Add switches 
 ovs1 = add_ovs(ec, "nepi_bridge", "192.168.3.1/24", "85.23.168.77", "6633", s1_node)
@@ -96,12 +105,12 @@ port3 = add_port(ec, "nepi_port3", ovs1)
 port2 = add_port(ec, "nepi_port2", ovs2)
 port4 = add_port(ec, "nepi_port4", ovs2)
 
-h1_node = add_node(ec, host1, slicename)
-h2_node = add_node(ec, host2, slicename
+h1_node = add_node(ec, host1, slicename, pl_user, pl_password)
+h2_node = add_node(ec, host2, slicename, pl_user, pl_password)
 
 # Add tap devices
 tap1 = add_tap(ec, "192.168.3.3", 24, "192.168.3.1", h1_node)
-tap2 = add_tap(ec, "192.168.3.4", 24, "192.168.3.1", h2_node)
+tap2 = add_tap(ec, "192.168.3.4", 24, "192.168.3.2", h2_node)
 
 # Connect the nodes
 tunnel1 = add_tunnel(ec, port1, tap1)
@@ -113,6 +122,7 @@ app1 = add_app(ec, "ping -c3 192.168.3.3", s1_node)
 app2 = add_app(ec, "ping -c3 192.168.3.4", s2_node)
 
 ec.deploy()
+
 ec.wait_finished([app2])
 
 # Retreive ping results and save
index 842f5c2..32552e0 100644 (file)
@@ -153,19 +153,19 @@ class OVSWitch(LinuxApplication):
         """
         node = self.node
         if not node or node.state < ResourceState.READY:
-            self.debug("---- RESCHEDULING DEPLOY ---- node state %s " % self.node.state )
+            #self.debug("---- RESCHEDULING DEPLOY ---- node state %s " % self.node.state )
             self.ec.schedule(reschedule_delay, self.deploy)
-
-        else:
-            self.do_discover()
-            self.do_provision()
-            self.check_sliver_ovs()
-            self.servers_on()
-            self.create_bridge()
-            self.assign_contr()
-            self.ovs_status()
+            return
+
+        self.do_discover()
+        self.do_provision()
+        self.check_sliver_ovs()
+        self.servers_on()
+        self.create_bridge()
+        self.assign_controller()
+        self.ovs_status()
             
-            super(OVSWitch, self).do_deploy()
+        super(OVSWitch, self).do_deploy()
 
     def servers_on(self):
         """ Start the openvswitch servers and also checking 
@@ -222,36 +222,38 @@ class OVSWitch(LinuxApplication):
         # TODO: Add check for virtual_ip belonging to vsys_tag
         self.del_old_br()
        
-        if self.get("bridge_name") and self.get("virtual_ip_pref"):    
-            bridge_name = self.get("bridge_name")
-            virtual_ip_pref = self.get("virtual_ip_pref")
-            self.info(" Creating the bridge %s and assigning %s" %\
-                (bridge_name, virtual_ip_pref) )
-            cmd = "sliver-ovs create-bridge '%s' '%s'" %\
-                (bridge_name, virtual_ip_pref) 
-            out = err = ""
-            (out, err), proc = self.node.run_and_wait(cmd, self.ovs_checks,
-                    shfile = "create_br.sh",
-                    pidfile = "create_br_pidfile",
-                    ecodefile = "create_br_exitcode", 
-                    sudo = True, 
-                    stdout = "create_br_stdout", 
-                    stderr = "create_br_stderr") 
-            (out, err), proc = self.node.check_output(self.ovs_checks, 'create_br_exitcode')
-            if out != "0\n":
-                msg = "No such pltap netdev\novs-appctl: ovs-vswitchd: server returned an error"
-                self.debug("Check again the virtual IP")                       
-                raise RuntimeError, msg
-            self.info("Bridge %s created" % bridge_name)
-          
-        else:  
+        if not (self.get("bridge_name") and self.get("virtual_ip_pref")):
             msg = "No assignment in one or both attributes"
             self.error(msg)
             self.debug("Bridge name is %s and virtual_ip_pref is %s" %\
                 (self.get("bridge_name"), self.get("virtual_ip_pref")) )
             raise AttributeError, msg
+       
+        bridge_name = self.get("bridge_name")
+        virtual_ip_pref = self.get("virtual_ip_pref")
+        self.info(" Creating the bridge %s and assigning %s" %\
+            (bridge_name, virtual_ip_pref) )
+        cmd = "sliver-ovs create-bridge '%s' '%s'" %\
+            (bridge_name, virtual_ip_pref) 
+        out = err = ""
+        (out, err), proc = self.node.run_and_wait(cmd, self.ovs_checks,
+                shfile = "create_br.sh",
+                pidfile = "create_br_pidfile",
+                ecodefile = "create_br_exitcode", 
+                sudo = True, 
+                stdout = "create_br_stdout", 
+                stderr = "create_br_stderr") 
+
+        (out, err), proc = self.node.check_output(self.ovs_checks, 'create_br_exitcode')
+        if out != "0\n":
+            msg = "No such pltap netdev\novs-appctl: ovs-vswitchd: server returned an error"
+            self.debug("Check again the virtual IP")                   
+            raise RuntimeError, msg
+
+        self.info("Bridge %s created" % bridge_name)
+          
 
-    def assign_contr(self):
+    def assign_controller(self):
         """ Set the controller IP
         """
         if self.get("controller_ip") and self.get("controller_port"):
index ec5f6f1..a78c66a 100644 (file)
@@ -115,6 +115,7 @@ class OVSPort(LinuxApplication):
             msg = "info_list is empty"
             self.debug(msg)
             raise RuntimeError, msg
+
         import socket
         self.port_info.append(get_host_ip.get('hostname'))
         self.port_info.append(socket.gethostbyname(self.port_info[0]))   
@@ -123,6 +124,7 @@ class OVSPort(LinuxApplication):
         """ Create the desired port
         """
         port_name = self.get('port_name')
+
         if not (port_name or self.ovswitch):
             msg = "The rm_list is empty or the port name is not assigned\n Failed to create port"
             self.error(msg)
@@ -161,6 +163,7 @@ class OVSPort(LinuxApplication):
             self.error(msg)
             self.debug("You are in the method get_local_end and the port_name = %s" % self.get('port_name'))
             raise AttributeError, msg
+
         self._port_number = None
         self._port_number = int(out)
         self.port_info.append(self._port_number)                               
@@ -183,27 +186,29 @@ class OVSPort(LinuxApplication):
         """ Wait until ovswitch is started
         """
         ovswitch = self.ovswitch
+
         if not ovswitch or ovswitch.state < ResourceState.READY:       
             self.debug("---- RESCHEDULING DEPLOY ---- node state %s " % self.ovswitch.state )  
             self.ec.schedule(reschedule_delay, self.deploy)
-            
-        else:
-            self.do_discover()
-            self.do_provision()
-            self.get_host_ip()
-            self.create_port()
-            self.get_local_end()
-            self.ovswitch.ovs_status()
+            return
+
+        self.do_discover()
+        self.do_provision()
+        self.get_host_ip()
+        self.create_port()
+        self.get_local_end()
+        self.ovswitch.ovs_status()
 
-            super(OVSPort, self).do_deploy()
+        super(OVSPort, self).do_deploy()
 
     def do_release(self):
         """ Release the port RM means delete the ports
         """
         # OVS needs to wait until all associated RMs are released
         # to be released
-        from nepi.resources.planetlab.openvswitch.tunnel import Tunnel
-        rm = self.get_connected(Tunnel.rtype())
+        from nepi.resources.planetlab.openvswitch.tunnel import OVSTunnel
+        rm = self.get_connected(OVSTunnel.rtype())
+
         if rm and rm[0].state < ResourceState.FINISHED:
             self.ec.schedule(reschedule_delay, self.release)
             return 
index 8ae7393..e27a512 100644 (file)
@@ -100,9 +100,14 @@ class OVSTunnel(LinuxApplication):
         self._pid = None
         self._ppid = None
 
+
+    def log_message(self, msg):
+        return " guid %d - Tunnel - %s " % (self.guid, msg)
+
     @property
     def node(self):
-        return self._nodes[0]
+        if self._nodes:
+            return self._nodes[0]
 
     def app_home(self, node):
         return os.path.join(node.exp_home, self._home)
@@ -132,20 +137,17 @@ class OVSTunnel(LinuxApplication):
 
     def get_node(self, endpoint):
         # Get connected to the nodes
+        res = []
         if hasattr(endpoint, "create_port"):
-            res = []
             rm_list = endpoint.get_connected(OVSWitch.rtype())
             if rm_list:
                 rm = rm_list[0].get_connected(PlanetlabNode.rtype())
-                if rm: 
-                    res.append(rm[0])
-            return res
         else:
-            res = []
             rm = endpoint.get_connected(PlanetlabNode.rtype())
-            if rm :
-                res.append(rm[0])
-            return res
+
+        if rm :
+            res.append(rm[0])
+        return res
 
     @property
     def endpoint1(self):
@@ -172,8 +174,7 @@ class OVSTunnel(LinuxApplication):
         port_endpoints = self.port_endpoints()
         if len(port_endpoints) == 2:
             return True
-        else: 
-            return False
+        return False
 
     def get_port_info(self, endpoint, rem_endpoint):
         """ Retrieve the port_info list for each port
@@ -191,11 +192,10 @@ class OVSTunnel(LinuxApplication):
             host1, ip1, pname1, virt_ip1, pnumber1 = self.port_info_tunl[1]
             return (pname0, ip1, pnumber1)      
          
-        else:
-            # Use for the link host-->switch
-            self.port_info_tunl.append(endpoint.port_info)
-            host0, ip0, pname0, virt_ip0, pnumber0 = self.port_info_tunl[0]
-            return pnumber0
+        # Use for the link host-->switch
+        self.port_info_tunl.append(endpoint.port_info)
+        host0, ip0, pname0, virt_ip0, pnumber0 = self.port_info_tunl[0]
+        return pnumber0
     
     def udp_connect(self, endpoint, rem_endpoint):     
         # Collect info from rem_endpoint
@@ -248,7 +248,7 @@ class OVSTunnel(LinuxApplication):
 
         msg = "Connection on host %s configured" \
             % self.node.get("hostname")
-        self.info(msg)
+        self.debug(msg)
          
         # Wait for pid file to be generated
         self._nodes = self.get_node(endpoint) 
@@ -291,15 +291,14 @@ class OVSTunnel(LinuxApplication):
                 stderr = "sw_stderr")
         
         # check if execution errors occured
-        msg = "Failed to connect endpoints"
-
         if proc.poll():
+            msg = "Failed to connect endpoints"
             self.error(msg, out, err)
             raise RuntimeError, msg
-        else:
-            msg = "Connection on port %s configured" % local_port_name
-            self.info(msg)
-            return 
+
+        # For debugging
+        msg = "Connection on port %s configured" % local_port_name
+        self.info(msg)
 
     def sw_host_connect(self, endpoint, rem_endpoint):
         """Link switch--> host
@@ -323,23 +322,23 @@ class OVSTunnel(LinuxApplication):
                 text = True,
                 overwrite = False)
 
-        #invoke connect script
+        # Invoke connect script
         cmd = "bash %s" % shfile
         (out, err), proc = self.node.run(cmd, self.run_home(self.node),
                 sudo  = True,
                 stdout = "sw_stdout",
                 stderr = "sw_stderr")
         
-        # check if execution errors occured
-        msg = "Failed to connect endpoints"
+        # Check if execution errors occured
 
         if proc.poll():
+            msg = "Failed to connect endpoints"
             self.error(msg, out, err)
             raise RuntimeError, msg
-        else:
-            msg = "Connection on port %s configured" % local_port_name
-            self.info(msg)
-            return                                                      
+
+        # For debugging
+        msg = "Connection on port %s configured" % local_port_name
+        self.debug(msg)                                                   
 
     def do_provision(self):
         """ Provision the tunnel
@@ -352,13 +351,13 @@ class OVSTunnel(LinuxApplication):
 
         if self.check_endpoints():
             #Invoke connect script between switches
-            switch_connect1 = self.switch_connect(self.endpoint1, self.endpoint2)
-            switch_connect2 = self.switch_connect(self.endpoint2, self.endpoint1)
+            self.switch_connect(self.endpoint1, self.endpoint2)
+            self.switch_connect(self.endpoint2, self.endpoint1)
 
         else: 
             # Invoke connect script between switch & host
             (self._pid, self._ppid) = self.udp_connect(self.endpoint2, self.endpoint1)
-            switch_connect = self.sw_host_connect(self.endpoint1, self.endpoint2)
+            self.sw_host_connect(self.endpoint1, self.endpoint2)
 
         super(OVSTunnel, self).do_provision()
 
@@ -366,11 +365,12 @@ class OVSTunnel(LinuxApplication):
         if (not self.endpoint1 or self.endpoint1.state < ResourceState.READY) or \
             (not self.endpoint2 or self.endpoint2.state < ResourceState.READY):
             self.ec.schedule(reschedule_delay, self.deploy)
-        else:
-            self.do_discover()
-            self.do_provision()
+            return
+
+        self.do_discover()
+        self.do_provision()
 
-            super(OVSTunnel, self).do_deploy()
+        super(OVSTunnel, self).do_deploy()
  
     def do_release(self):
         """ Release the udp_tunnel on endpoint2.
@@ -383,7 +383,7 @@ class OVSTunnel(LinuxApplication):
                 self._nodes = self.get_node(self.endpoint2) 
                 (out, err), proc = self.node.kill(self._pid,
                         self._ppid, sudo = True)
-            if err or proc.poll():
+                if err or proc.poll():
                     # check if execution errors occurred
                     msg = " Failed to delete TAP device"
                     self.error(msg, err, err)