def _handle_ConnectionUp (event): # Set up this switch. # Turn on ability to specify table in flow_mods msg = nx.nx_flow_mod_table_id() event.connection.send(msg) # Clear second table msg = nx.nx_flow_mod(command=of.OFPFC_DELETE, table_id = 1) event.connection.send(msg) # Learning rule in table 0 msg = nx.nx_flow_mod() msg.table_id = 0 learn = nx.nx_action_learn(table_id=1,hard_timeout=10) learn.spec.chain( field=nx.NXM_OF_VLAN_TCI, n_bits=12).chain( field=nx.NXM_OF_ETH_SRC, match=nx.NXM_OF_ETH_DST).chain( field=nx.NXM_OF_IN_PORT, output=True) msg.actions.append(learn) msg.actions.append(nx.nx_action_resubmit.resubmit_table(1)) event.connection.send(msg) # Fallthrough rule for table 1: flood msg = nx.nx_flow_mod() msg.table_id = 1 msg.priority = 1 # Low priority msg.actions.append(of.ofp_action_output(port = of.OFPP_FLOOD)) event.connection.send(msg)
def broadcast_paths (self): # tell all switches what ports to send out broadcast packets self.MST = nx.minimum_spanning_tree(self.graph) switches = {} for edge in self.MST.edges(data=True): #self.log.info(edge) src = edge[0] dst = edge[1] if src in edge[2]['ports']: src_outport = edge[2]['ports'][src] if src in switches: switches[src].append(src_outport) else: switches[src] = [src_outport] if dst in edge[2]['ports']: dst_outport = edge[2]['ports'][dst] if dst in switches: switches[dst].append(dst_outport) else: switches[dst] = [dst_outport] for switch, ports in switches.items(): if 'dpid' not in self.graph.node[switch]: continue switch_dpid = self.graph.node[switch]['dpid'] core.openflow.sendToDPID(switch_dpid, nx_flow_mod_table_id()) out_actions = [ofp_action_output(port=p) for p in ports] fm = ofp_flow_mod_table_id( table_id = 0, command = of01.OFPFC_MODIFY, match = of01.ofp_match(dl_dst=ETHER_BROADCAST), actions = out_actions) core.openflow.sendToDPID(switch_dpid, fm.pack())
def _handle_openflow_ConnectionUp (self, e): """ Handle the case when your connection to a switch goes up You can now control this switch. """ self.log.info("Switch [%s] has gone up", dpid_to_str(e.dpid)) e.connection.send(nx_flow_mod_table_id()) # Enables multiple tables switch_name = self.graph.names[e.dpid] if switch_name not in self.graph: zombie = self.down_switches[switch_name] self.graph.add_node(switch_name) self.graph.node[switch_name] = zombie[0] for edge in zombie[1]: self.graph.add_edge(switch_name, edge) self.graph.add_edge(edge, switch_name) self.graph.edge[switch_name][edge] = zombie[1][edge] self.graph.edge[edge][switch_name] = zombie[1][edge] del self.down_switches[switch_name] self.shortest_paths_to_switches() self.broadcast_paths()
def _handle_ConnectionUp(self, event): assert event.dpid not in self.switches self.switches[event.dpid] = {} self.switches[event.dpid]['connection'] = event.connection self.switches[event.dpid]['ports'] = {} if self.use_nx: """ Enable nicira packet-ins (e.g., to get rule cookies) """ msg = nx.nx_packet_in_format() self.switches[event.dpid]['connection'].send(msg) """ Enable multi-stage table with nicira extensions """ msg = nx.nx_flow_mod_table_id() self.switches[event.dpid]['connection'].send(msg) self.__nx_switch_pipeline_init(event.dpid, self.pipeline) else: msg = of.ofp_flow_mod(match = of.ofp_match()) msg.actions.append(of.ofp_action_output(port = of.OFPP_CONTROLLER)) self.switches[event.dpid]['connection'].send(msg) self.send_to_pyretic(['switch','join',event.dpid,'BEGIN']) # port type is ofp_phy_port for port in event.ofp.ports: if port.port_no <= of.OFPP_MAX: self.switches[event.dpid]['ports'][port.port_no] = port.hw_addr CONF_UP = not 'OFPPC_PORT_DOWN' in self.active_ofp_port_config(port.config) STAT_UP = not 'OFPPS_LINK_DOWN' in self.active_ofp_port_state(port.state) PORT_TYPE = self.active_ofp_port_features(port.curr) self.send_to_pyretic(['port','join',event.dpid, port.port_no, CONF_UP, STAT_UP, PORT_TYPE]) self.send_to_pyretic(['switch','join',event.dpid,'END'])
def shortest_paths_to_switches (self): # tell all switches what their next hop is to all other switches (for shortest paths) all_paths = nx.shortest_path(self.graph) for src, paths in all_paths.items(): if 'dpid' not in self.graph.node[src]: continue src_dpid = self.graph.node[src]['dpid'] if core.openflow.getConnection(src_dpid): core.openflow.sendToDPID(src_dpid, nx_flow_mod_table_id()) # Enables multiple tables data = [] for dst, path in paths.items(): if dst == src: continue if 'dpid' not in self.graph.node[dst]: continue dst_dpid = self.graph.node[dst]['dpid'] #self.log.info(str(src_dpid) + ' --> ' + str(dst_dpid) + ' : ' + str(path)) next_hop = path[1] shortest_path_port = self.graph[src][next_hop]['ports'][src] fm = ofp_flow_mod_table_id( table_id = 0, command = of01.OFPFC_MODIFY, match = of01.ofp_match(dl_vlan=dst_dpid), actions = [ofp_action_output(port=shortest_path_port)]) data.append(fm.pack()) core.openflow.sendToDPID(src_dpid, b''.join(data))
def _handle_ConnectionUp(event): # Set up this switch. # Turn on ability to specify table in flow_mods msg = nx.nx_flow_mod_table_id() event.connection.send(msg) # Clear second table msg = nx.nx_flow_mod(command=of.OFPFC_DELETE, table_id=1) event.connection.send(msg) # Learning rule in table 0 msg = nx.nx_flow_mod() msg.table_id = 0 learn = nx.nx_action_learn(table_id=1, hard_timeout=10) learn.spec.chain(field=nx.NXM_OF_VLAN_TCI, n_bits=12).chain(field=nx.NXM_OF_ETH_SRC, match=nx.NXM_OF_ETH_DST).chain( field=nx.NXM_OF_IN_PORT, output=True) msg.actions.append(learn) msg.actions.append(nx.nx_action_resubmit.resubmit_table(1)) event.connection.send(msg) # Fallthrough rule for table 1: flood msg = nx.nx_flow_mod() msg.table_id = 1 msg.priority = 1 # Low priority msg.actions.append(of.ofp_action_output(port=of.OFPP_FLOOD)) event.connection.send(msg)
def _handle_openflow_ConnectionUp(self, event): if event.dpid != self.dpid: return self.log.info("Switch connected") self._conn.send(ovs.nx_flow_mod_table_id()) self._conn.send(ovs.nx_packet_in_format()) self._init_tables() self._refresh_ports() self._invalidate()
def _handle_ConnectionUp(self, event): msg = nx.nx_packet_in_format() event.connection.send(msg) msg = nx.nx_flow_mod_table_id() event.connection.send(msg) msg = nx.nx_flow_mod(command=of.OFPFC_DELETE) msg.table_id = 1 event.connection.send(msg)
def _handle_ConnectionUp(self, event): msg = nx.nx_packet_in_format() event.connection.send(msg) msg = nx.nx_flow_mod_table_id() event.connection.send(msg) msg = nx.nx_flow_mod(command = of.OFPFC_DELETE) msg.table_id = 1 event.connection.send(msg)
def _handle_ConnectionUp (event): #When a switch connects, create a new node in graph global num_switches global g num_switches += 1 g[event.dpid] = [ [-1,-1] for i in range(num_pods)] all_switches.add(event.dpid) # Turn on ability to specify table in flow_mods msg = nx.nx_flow_mod_table_id() event.connection.send(msg)
def _handle_ViroSwitchUp(self, event): """ Local VIRO switch is connecting to the local controller We set the controller Id to our local VIRO controller """ log.debug("Connection %s %s" % (event.connection, dpidToStr(event.dpid))) self.sw.dpid = event.dpid self.sw.connection = event.connection self.routing.dpid = event.dpid self.routing.routingTable.dpid = event.dpid # Guobao added 02/05/2015 #self.previousRoutingTable = copy.deepcopy(self.routing.routingTable) self.previousRoutingTable = RoutingTable(None, None) # Turn on ability to specify table in flow_mods msg = nx.nx_flow_mod_table_id() self.sw.connection.send(msg) msg = msgFactory.ofpControllerId(LocalViro.CONTROLLER_ID) self.sw.connection.send(msg) msg = msgFactory.ctrlPktsLocalViroPacketIn( LocalViro.CONTROLLER_ID) # set the rule for Viro Packets self.sw.connection.send(msg) msg_ip = msgFactory.IPv4LocalViroPacketIn( LocalViro.CONTROLLER_ID) # set the rule for IP Packets self.sw.connection.send(msg_ip) # Guobao -- Fallback rule for Table 0 msg = msgFactory.FallBack(1) self.sw.connection.send(msg) # Start periodic function of the local controller # 1. Neighbor discovery # 2. Routing table rounds # 3. Failure discovery # We don't use recurring timers to avoid function call overlaps in case of delays # So, we call the timer function after the end of the callback function Timer(LocalViro.DISCOVER_TIME, self.neibghoorDiscoverCallback) #Timer(LocalViro.FAILURE_TIME, self.discoveryFailureCallback) # comment here self.round = 1 Timer(LocalViro.UPDATE_RT_TIME, self.startRoundCallback) # Sync RT Table every UPDATE_RT_TIME? Timer(LocalViro.UPDATE_RT_TIME, self.pushRTHelper)
def __init__(self, connection): topo = TopologyManager() self.connection = connection connection.addListeners(self) l = {} print(topo.switches) if (connection.eth_addr.toStr() in topo.switches): print("Connected") for k, v in topo.links.items(): if connection.eth_addr.toStr() in v: i = 1 for k, v in l.items(): print('Installing rule for link', k, 'table', i) msg = nx.nx_flow_mod_table_id() connection.send(msg) # table 0 msg = nx.nx_flow_mod() msg.table_id = 0 msg.priority = 1500 msg.match.of_eth_dst = "00:00:00:00:00:00" msg.match.of_eth_type = 0x86dd msg.match.of_in_port = v[0] msg.actions.append( nx.nx_action_resubmit.resubmit_table(table=0)) self.connection.send(msg) msg = nx.nx_flow_mod() msg.table_id = 0 msg.priority = 1000 msg.match.of_eth_dst = "00:00:00:00:00:00" msg.match.of_eth_type = 0x86dd msg.match.nx_ipv6_dst = (IPAddr6("::2"), IPAddr6("::2")) msg.actions.append(of.ofp_action_output(port=v[1])) msg.actions.append( nx.nx_action_resubmit.resubmit_table(table=0)) self.connection.send(msg) if i != topo.links.__len__(): msg = nx.nx_flow_mod() msg.table_id = 0 msg.priority = 500 msg.match.of_eth_dst = "00:00:00:00:00:00" msg.match.of_eth_type = 0x86dd msg.actions.append( nx.nx_action_resubmit.resubmit_table(table=1)) self.connection.send(msg) i += 1
def _handle_ConnectionUp(event): #When a switch connects, create a new node in graph global num_switches num_switches += 1 #g[event.dpid] = [ [-1,-1] for i in range(num_pods)] g[event.dpid] = {} switch_pos[event.dpid] = [-1, -1] l = [port.port_no for port in event.ofp.ports] if of.OFPP_LOCAL in l: #removing the openflow local port l.remove(of.OFPP_LOCAL) total_ports[event.dpid] = len(l) ports[event.dpid] = l all_switches.add(event.dpid) # Turn on ability to specify table in flow_mods msg = nx.nx_flow_mod_table_id() event.connection.send(msg)
def _handle_ConnectionUp (event): #When a switch connects, create a new node in graph global num_switches num_switches += 1 #g[event.dpid] = [ [-1,-1] for i in range(num_pods)] g[event.dpid] = {} switch_pos[event.dpid] = [-1, -1] l = [port.port_no for port in event.ofp.ports] if of.OFPP_LOCAL in l: #removing the openflow local port l.remove(of.OFPP_LOCAL) total_ports[event.dpid] = len(l) ports[event.dpid] = l all_switches.add(event.dpid) # Turn on ability to specify table in flow_mods msg = nx.nx_flow_mod_table_id() event.connection.send(msg)
def _handle_ConnectionUp (event): # Set up this switch. # After setting up, we send a barrier and wait for the response # before starting to listen to packet_ins for this switch -- before # the switch is set up, the packet_ins may not be what we expect, # and our responses may not work! # Turn on Nicira packet_ins msg = nx.nx_packet_in_format() event.connection.send(msg) # Turn on ability to specify table in flow_mods msg = nx.nx_flow_mod_table_id() event.connection.send(msg) # Clear second table msg = nx.nx_flow_mod(command=of.OFPFC_DELETE, table_id = 1) event.connection.send(msg) # Fallthrough rule for table 0: flood and send to controller msg = nx.nx_flow_mod() msg.priority = 1 # Low priority msg.actions.append(of.ofp_action_output(port = of.OFPP_CONTROLLER)) msg.actions.append(nx.nx_action_resubmit.resubmit_table(table = 1)) event.connection.send(msg) # Fallthrough rule for table 1: flood msg = nx.nx_flow_mod() msg.table_id = 1 msg.actions.append(of.ofp_action_output(port = of.OFPP_FLOOD)) event.connection.send(msg) def ready (event): if event.ofp.xid != 0x80000000: # Not the right barrier return log.info("%s ready", event.connection) event.connection.addListenerByName("PacketIn", _handle_PacketIn) return EventRemove event.connection.send(of.ofp_barrier_request(xid=0x80000000)) event.connection.addListenerByName("BarrierIn", ready)
def _handle_ConnectionUp(event): # Set up this switch. # After setting up, we send a barrier and wait for the response # before starting to listen to packet_ins for this switch -- before # the switch is set up, the packet_ins may not be what we expect, # and our responses may not work! # Turn on Nicira packet_ins msg = nx.nx_packet_in_format() event.connection.send(msg) # Turn on ability to specify table in flow_mods msg = nx.nx_flow_mod_table_id() event.connection.send(msg) # Clear second table msg = nx.nx_flow_mod(command=of.OFPFC_DELETE, table_id=1) event.connection.send(msg) # Fallthrough rule for table 0: flood and send to controller msg = nx.nx_flow_mod() msg.priority = 1 # Low priority msg.actions.append(of.ofp_action_output(port=of.OFPP_CONTROLLER)) msg.actions.append(nx.nx_action_resubmit.resubmit_table(table=1)) event.connection.send(msg) # Fallthrough rule for table 1: flood msg = nx.nx_flow_mod() msg.table_id = 1 msg.priority = 1 # Low priority msg.actions.append(of.ofp_action_output(port=of.OFPP_FLOOD)) event.connection.send(msg) def ready(event): if event.ofp.xid != 0x80000000: # Not the right barrier return log.info("%s ready", event.connection) event.connection.addListenerByName("PacketIn", _handle_PacketIn) return EventRemove event.connection.send(of.ofp_barrier_request(xid=0x80000000)) event.connection.addListenerByName("BarrierIn", ready)
def _handle_ConnectionUp(event): # Initialize the forwarding rules for this switch. # After setting up, we send a barrier and wait for the response # before starting to listen to packet_ins for this switch -- before # the switch is set up, the packet_ins may not be what we expect, # and our responses may not work! connection = event.connection dpid = connection.dpid print "handle_ConnectionUP from dpid", dpid, util.dpid_to_str(dpid) portlist = connection.ports.values() # get port_no of each item in portlist portlist = map(lambda x: x.port_no, portlist) portlist = filter(lambda x: x < of.OFPP_MAX, portlist) # Turn on Nicira packet_ins msg = nx.nx_packet_in_format() connection.send(msg) # Turn on this switch's ability to specify tables in flow_mods msg = nx.nx_flow_mod_table_id() connection.send(msg) # Clear first table msg = nx.nx_flow_mod(command=of.OFPFC_DELETE, table_id=0) connection.send(msg) # Clear second table msg = nx.nx_flow_mod(command=of.OFPFC_DELETE, table_id=1) connection.send(msg) # this version sets default flooding actions only for ICMP and ARP packets # (though there IS a rule to send unknown packets to the controller) # Default rule for table 0: flood (IF a flooder) and send to table 1 # Default rule for table 1: send to controller # Default rule for table 0 starts here msgi = nx.nx_flow_mod() # icmp msg msga = nx.nx_flow_mod() # arp msg msgi.table_id = msga.table_id = 0 msgi.priority = msga.priority = 1 # Low priority msgi.idle_timeout = msga.idle_timeout = ICMP_IDLE_TIMEOUT msgi.match.append(nx.NXM_OF_ETH_TYPE(pkt.ethernet.IP_TYPE)) msgi.match.append(nx.NXM_OF_IP_PROTO(pkt.ipv4.ICMP_PROTOCOL)) msga.match.append(nx.NXM_OF_ETH_TYPE(pkt.ethernet.ARP_TYPE)) if flooder(dpid): msgi.actions.append(of.ofp_action_output(port=of.OFPP_FLOOD)) msga.actions.append(of.ofp_action_output(port=of.OFPP_FLOOD)) msgi.actions.append(nx.nx_action_resubmit.resubmit_table(table=1)) msga.actions.append(nx.nx_action_resubmit.resubmit_table(table=1)) connection.send(msgi) connection.send(msga) # Default rule for table 1: send to controller msgi = nx.nx_flow_mod() # icmp msg msga = nx.nx_flow_mod() # arp msg msgi.table_id = msga.table_id = 1 msgi.priority = msga.priority = 1 # Low priority msgi.idle_timeout = msga.idle_timeout = ICMP_IDLE_TIMEOUT msgi.match.append(nx.NXM_OF_ETH_TYPE(pkt.ethernet.IP_TYPE)) msgi.match.append(nx.NXM_OF_IP_PROTO(pkt.ipv4.ICMP_PROTOCOL)) msga.match.append(nx.NXM_OF_ETH_TYPE(pkt.ethernet.ARP_TYPE)) msgi.actions.append(of.ofp_action_output(port=of.OFPP_CONTROLLER)) msga.actions.append(of.ofp_action_output(port=of.OFPP_CONTROLLER)) connection.send(msgi) connection.send(msga) if flooder( dpid ): # create emtpy default action (applies mostly to TCP traffic) msgdef = nx.nx_flow_mod() msgdef.table_id = 0 msgdef.priority = 0 # pld: MUST HAVE THIS msgdef.actions.append(of.ofp_action_output(port=of.OFPP_CONTROLLER)) connection.send(msgdef) def ready(event): # called right below, as parameter if event.ofp.xid != 0x80000000: # Not the right barrier return log.info("%s ready", event.connection) event.connection.addListenerByName("PacketIn", _handle_PacketIn) return EventRemove # the following is to ensure that the switch does nothing else until it processes the actions above connection.send(of.ofp_barrier_request(xid=0x80000000)) connection.addListenerByName("BarrierIn", ready) # now install switch if dpid in switchmap: sw = switchmap[dpid] if sw.connection() is None: sw.setConnection(connection) else: sw = SwitchNode(dpid, connection) switchmap[dpid] = sw # now add empty port list sw.setUnknownPorts(portlist)
def __init__(self, connection): self.connection = connection connection.addListeners(self) if (connection.eth_addr.toStr() == "00:00:00:00:00:01"): print "Preparing of rules" msg = nx.nx_flow_mod_table_id() connection.send(msg) #table 0 msg = nx.nx_flow_mod() msg.table_id = 0 msg.priority = 1500 msg.match.of_eth_dst = "00:00:00:00:00:00" msg.match.of_eth_type = 0x86dd msg.match.of_in_port = 1 msg.actions.append(nx.nx_action_resubmit.resubmit_table(table=1)) self.connection.send(msg) msg = nx.nx_flow_mod() msg.table_id = 0 msg.priority = 1000 msg.match.of_eth_dst = "00:00:00:00:00:00" msg.match.of_eth_type = 0x86dd msg.match.nx_ipv6_dst = (IPAddr6("::1"), IPAddr6("::1")) msg.actions.append(of.ofp_action_output(port=1)) msg.actions.append(nx.nx_action_resubmit.resubmit_table(table=1)) self.connection.send(msg) msg = nx.nx_flow_mod() msg.table_id = 0 msg.priority = 500 msg.match.of_eth_dst = "00:00:00:00:00:00" msg.match.of_eth_type = 0x86dd msg.actions.append(nx.nx_action_resubmit.resubmit_table(table=1)) self.connection.send(msg) #table 1 msg = nx.nx_flow_mod() msg.table_id = 1 msg.priority = 1000 msg.match.of_eth_dst = "00:00:00:00:00:00" msg.match.of_eth_type = 0x86dd msg.match.nx_ipv6_dst = (IPAddr6("::2"), IPAddr6("::2")) msg.actions.append(of.ofp_action_output(port=1)) self.connection.send(msg) msg = nx.nx_flow_mod() msg.table_id = 1 msg.priority = 1500 msg.match.of_eth_dst = "00:00:00:00:00:00" msg.match.of_eth_type = 0x86dd msg.match.of_in_port = 2 self.connection.send(msg) if (connection.eth_addr.toStr() == "00:00:00:00:00:02"): print "Preparing of rules" msg = nx.nx_flow_mod_table_id() connection.send(msg) #table 0 msg = nx.nx_flow_mod() msg.table_id = 0 msg.priority = 1500 msg.match.of_eth_dst = "00:00:00:00:00:00" msg.match.of_eth_type = 0x86dd msg.match.of_in_port = 1 msg.actions.append(nx.nx_action_resubmit.resubmit_table(table=1)) self.connection.send(msg) msg = nx.nx_flow_mod() msg.table_id = 0 msg.priority = 1000 msg.match.of_eth_dst = "00:00:00:00:00:00" msg.match.of_eth_type = 0x86dd msg.match.nx_ipv6_dst = (IPAddr6("::2"), IPAddr6("::2")) msg.actions.append(of.ofp_action_output(port=1)) msg.actions.append(nx.nx_action_resubmit.resubmit_table(table=1)) self.connection.send(msg) msg = nx.nx_flow_mod() msg.table_id = 0 msg.priority = 500 msg.match.of_eth_dst = "00:00:00:00:00:00" msg.match.of_eth_type = 0x86dd msg.actions.append(nx.nx_action_resubmit.resubmit_table(table=1)) self.connection.send(msg) #table 1 msg = nx.nx_flow_mod() msg.table_id = 1 msg.priority = 1000 msg.match.of_eth_dst = "00:00:00:00:00:00" msg.match.of_eth_type = 0x86dd msg.match.nx_ipv6_dst = (IPAddr6("::4"), IPAddr6("::4")) msg.actions.append(of.ofp_action_output(port=2)) self.connection.send(msg) msg = nx.nx_flow_mod() msg.table_id = 1 msg.priority = 1500 msg.match.of_eth_dst = "00:00:00:00:00:00" msg.match.of_eth_type = 0x86dd msg.match.of_in_port = 2 self.connection.send(msg)
def _handle_ConnectionUp(self, event): # Initialize Nicira msg = nx.nx_flow_mod() event.connection.send(msg) # Signal Table use msg = nx.nx_flow_mod_table_id() event.connection.send(msg) #Table 1 -> TCP Table 2 -> ARP for temp_table_id in range(1, 5): msg = nx.nx_flow_mod(command=of.OFPFC_DELETE, table_id = temp_table_id) event.connection.send(msg) #Table 0 rule: Selection of tables #IP Packet Handling / TCP msg = nx.nx_flow_mod() msg.table_id = 0 msg.match.eth_type = pkt.ethernet.IP_TYPE msg.match.ip_proto = ipv4.TCP_PROTOCOL msg.priority = 65000 msg.actions.append(nx.nx_multipath(dst = nx.NXM_NX_REG2)) msg.actions.append(nx.nx_action_resubmit.resubmit_table(table = 1)) event.connection.send(msg) #ARP Packet Handling msg = nx.nx_flow_mod() msg.table_id = 0 msg.priority = 65001 msg.match.eth_type = pkt.ethernet.ARP_TYPE msg.actions.append(nx.nx_action_resubmit.resubmit_table(table = 4)) event.connection.send(msg) log.info("Table 0 done") #Table 1 Rules # TBD: State Machine and Hash value # New flow function msg = nx.nx_flow_mod() msg.table_id = 1 msg.match.eth_type = pkt.ethernet.IP_TYPE msg.match.ip_proto = ipv4.TCP_PROTOCOL msg.priority = 65004 # Signifying New flow msg.actions.append(nx.nx_reg_load(dst=nx.NXM_NX_REG0, value=0x0)) # currently learning based on eth address # no hash msg.actions.append(nx.nx_action_resubmit.resubmit_table(table = 2)) event.connection.send(msg) #Table 2 Rules #1. Sync (Should be a Sync) msg = nx.nx_flow_mod() msg.table_id = 2 msg.match.eth_type = pkt.ethernet.IP_TYPE msg.match.ip_proto = ipv4.TCP_PROTOCOL msg.match.NXM_NX_REG0 = 0 msg.match.tcp_flags = 2 msg.priority = 65001 # learn function for table 1 learn = nx.nx_action_learn(table_id=1,priority=65111) learn.spec = [ nx.flow_mod_spec(src=nx.nx_learn_src_field(nx.NXM_NX_REG2), dst=nx.nx_learn_dst_match(nx.NXM_NX_REG2)), ] fms = nx.flow_mod_spec.new learn.spec.append(fms(load=nx.NXM_NX_REG0, src=nx.nx_learn_src_immediate.u32(None, 1))) learn.spec.append(fms(field=nx.NXM_NX_REG0, reserved=True )) msg.actions.append(learn) msg.actions.append(nx.nx_action_resubmit.resubmit_table(table = 3)) event.connection.send(msg) #2. Sync Ack (Should be after sync) msg = nx.nx_flow_mod() msg.table_id = 2 msg.match.eth_type = pkt.ethernet.IP_TYPE msg.match.ip_proto = ipv4.TCP_PROTOCOL msg.match.tcp_flags = 0x12 msg.priority = 65002 msg.match.NXM_NX_REG0 = 1 # learn function for table 1 learn = nx.nx_action_learn(table_id=1,priority=65111) learn.spec = [ nx.flow_mod_spec(src=nx.nx_learn_src_field(nx.NXM_NX_REG2), dst=nx.nx_learn_dst_match(nx.NXM_NX_REG2)), ] fms = nx.flow_mod_spec.new learn.spec.append(fms(load=nx.NXM_NX_REG0, src=nx.nx_learn_src_immediate.u32(None, 2))) learn.spec.append(fms(field=nx.NXM_NX_REG0, reserved=True )) msg.actions.append(learn) msg.actions.append(nx.nx_action_resubmit.resubmit_table(table = 3)) event.connection.send(msg) #3. Ack msg = nx.nx_flow_mod() msg.table_id = 2 msg.match.eth_type = pkt.ethernet.IP_TYPE msg.match.ip_proto = ipv4.TCP_PROTOCOL msg.match.tcp_flags = 0x010 msg.priority = 65003 msg.match.NXM_NX_REG0 = 2 # learn function for table 1 learn = nx.nx_action_learn(table_id=1,priority=65111) learn.spec = [ nx.flow_mod_spec(src=nx.nx_learn_src_field(nx.NXM_NX_REG2), dst=nx.nx_learn_dst_match(nx.NXM_NX_REG2)), ] fms = nx.flow_mod_spec.new learn.spec.append(fms(load=nx.NXM_NX_REG0, src=nx.nx_learn_src_immediate.u32(None, 3))) learn.spec.append(fms(field=nx.NXM_NX_REG0, reserved=True )) msg.actions.append(learn) msg.actions.append(nx.nx_action_resubmit.resubmit_table(table = 3)) event.connection.send(msg) #4. Fin msg = nx.nx_flow_mod() msg.table_id = 2 msg.match.eth_type = pkt.ethernet.IP_TYPE msg.match.ip_proto = ipv4.TCP_PROTOCOL msg.match.tcp_flags = 0x010 msg.priority = 65003 msg.match.NXM_NX_REG0 = 3 # learn function for table 1 learn = nx.nx_action_learn(table_id=1,priority=65111) learn.spec = [ nx.flow_mod_spec(src=nx.nx_learn_src_field(nx.NXM_NX_REG2), dst=nx.nx_learn_dst_match(nx.NXM_NX_REG2)), ] fms = nx.flow_mod_spec.new learn.spec.append(fms(load=nx.NXM_NX_REG0, src=nx.nx_learn_src_immediate.u32(None, 4))) learn.spec.append(fms(field=nx.NXM_NX_REG0, reserved=True )) msg.actions.append(learn) msg.actions.append(nx.nx_action_resubmit.resubmit_table(table = 3)) event.connection.send(msg) #5. Fin-Ack msg = nx.nx_flow_mod() msg.table_id = 2 msg.match.eth_type = pkt.ethernet.IP_TYPE msg.match.ip_proto = ipv4.TCP_PROTOCOL msg.match.tcp_flags = 0x010 msg.priority = 65003 msg.match.NXM_NX_REG0 = 4 # learn function for table 1 learn = nx.nx_action_learn(table_id=1,priority=65111) learn.spec = [ nx.flow_mod_spec(src=nx.nx_learn_src_field(nx.NXM_NX_REG2), dst=nx.nx_learn_dst_match(nx.NXM_NX_REG2)), ] fms = nx.flow_mod_spec.new learn.spec.append(fms(load=nx.NXM_NX_REG0, src=nx.nx_learn_src_immediate.u32(None, 5))) learn.spec.append(fms(field=nx.NXM_NX_REG0, reserved=True )) msg.actions.append(learn) msg.actions.append(nx.nx_action_resubmit.resubmit_table(table = 3)) event.connection.send(msg) #7. Ack msg = nx.nx_flow_mod() msg.table_id = 2 msg.match.eth_type = pkt.ethernet.IP_TYPE msg.match.ip_proto = ipv4.TCP_PROTOCOL msg.match.tcp_flags = 0x010 msg.priority = 65003 msg.match.NXM_NX_REG0 = 5 # learn function for table 1 learn = nx.nx_action_learn(table_id=1,priority=65111) learn.spec = [ nx.flow_mod_spec(src=nx.nx_learn_src_field(nx.NXM_NX_REG2), dst=nx.nx_learn_dst_match(nx.NXM_NX_REG2)), ] fms = nx.flow_mod_spec.new learn.spec.append(fms(load=nx.NXM_NX_REG0, src=nx.nx_learn_src_immediate.u32(None, 6))) learn.spec.append(fms(field=nx.NXM_NX_REG0, reserved=True )) msg.actions.append(learn) msg.actions.append(nx.nx_action_resubmit.resubmit_table(table = 3)) event.connection.send(msg) #8. RST msg = nx.nx_flow_mod() msg.table_id = 2 msg.match.eth_type = pkt.ethernet.IP_TYPE msg.match.ip_proto = ipv4.TCP_PROTOCOL msg.match.tcp_flags = 0x14 msg.priority = 65003 msg.actions.append(nx.nx_action_resubmit.resubmit_table(table = 3)) event.connection.send(msg) #9. PSH-Ack msg = nx.nx_flow_mod() msg.table_id = 2 msg.match.eth_type = pkt.ethernet.IP_TYPE msg.match.ip_proto = ipv4.TCP_PROTOCOL msg.match.tcp_flags = 0x18 msg.priority = 65003 msg.actions.append(nx.nx_action_resubmit.resubmit_table(table = 3)) event.connection.send(msg) #9. Ack msg = nx.nx_flow_mod() msg.table_id = 2 msg.match.eth_type = pkt.ethernet.IP_TYPE msg.match.ip_proto = ipv4.TCP_PROTOCOL msg.match.tcp_flags = 0x10 msg.priority = 65003 msg.actions.append(nx.nx_action_resubmit.resubmit_table(table = 3)) event.connection.send(msg) #send to controller currently sending to the destination as no old state stored msg = nx.nx_flow_mod() msg.table_id = 2 msg.priority = 64999 msg.actions.append(nx.nx_reg_load(dst=nx.NXM_NX_REG1, value=int(1))) msg.actions.append(nx.nx_action_resubmit.resubmit_table(table = 3)) event.connection.send(msg) log.info("Table 2 done") #Table 3 Rules: Forward the packet to the Destination msg = nx.nx_flow_mod() msg.table_id = 3 msg.match.eth_type = pkt.ethernet.IP_TYPE msg.match.ip_dst = "10.0.0.1" msg.priority = 65001 msg.actions.append(of.ofp_action_output(port = 1)) event.connection.send(msg) msg = nx.nx_flow_mod() msg.table_id = 3 msg.match.eth_type = pkt.ethernet.IP_TYPE msg.match.ip_dst = "10.0.0.2" msg.priority = 65001 msg.actions.append(of.ofp_action_output(port = 2)) event.connection.send(msg) msg = nx.nx_flow_mod() msg.table_id = 3 msg.match.eth_type = pkt.ethernet.IP_TYPE msg.match.ip_dst = "10.0.0.3" msg.priority = 65001 msg.actions.append(of.ofp_action_output(port = 3)) event.connection.send(msg) #send to controller msg = nx.nx_flow_mod() msg.table_id = 3 msg.match.NXM_NX_REG1 = 1 msg.priority = 65005 msg.actions.append(of.ofp_action_output(port = of.OFPP_CONTROLLER)) event.connection.send(msg) log.info("Table 3 done") #Table 4 Rules msg = nx.nx_flow_mod() msg.table_id = 4 msg.actions.append(of.ofp_action_output(port = of.OFPP_FLOOD)) event.connection.send(msg) log.info("Table 4 done")
def _handle_ConnectionUp(self, event): # Initialize Nicira msg = nx.nx_flow_mod() event.connection.send(msg) # Signal Table use msg = nx.nx_flow_mod_table_id() event.connection.send(msg) #Table 1 -> TCP Table 2 -> ARP for temp_table_id in range(1, 5): msg = nx.nx_flow_mod(command=of.OFPFC_DELETE, table_id=temp_table_id) event.connection.send(msg) #Table 0 rule: Selection of tables #IP Packet Handling / TCP msg = nx.nx_flow_mod() msg.table_id = 0 msg.match.eth_type = pkt.ethernet.IP_TYPE msg.match.ip_proto = ipv4.TCP_PROTOCOL msg.priority = 65000 msg.actions.append(nx.nx_multipath(dst=nx.NXM_NX_REG2)) msg.actions.append(nx.nx_action_resubmit.resubmit_table(table=1)) event.connection.send(msg) #ARP Packet Handling msg = nx.nx_flow_mod() msg.table_id = 0 msg.priority = 65001 msg.match.eth_type = pkt.ethernet.ARP_TYPE msg.actions.append(nx.nx_action_resubmit.resubmit_table(table=4)) event.connection.send(msg) log.info("Table 0 done") #Table 1 Rules # TBD: State Machine and Hash value # New flow function msg = nx.nx_flow_mod() msg.table_id = 1 msg.match.eth_type = pkt.ethernet.IP_TYPE msg.match.ip_proto = ipv4.TCP_PROTOCOL msg.priority = 65004 # Signifying New flow msg.actions.append(nx.nx_reg_load(dst=nx.NXM_NX_REG0, value=0x0)) # currently learning based on eth address # no hash msg.actions.append(nx.nx_action_resubmit.resubmit_table(table=2)) event.connection.send(msg) #Table 2 Rules #1. Sync (Should be a Sync) msg = nx.nx_flow_mod() msg.table_id = 2 msg.match.eth_type = pkt.ethernet.IP_TYPE msg.match.ip_proto = ipv4.TCP_PROTOCOL msg.match.NXM_NX_REG0 = 0 msg.match.tcp_flags = 2 msg.priority = 65001 # learn function for table 1 learn = nx.nx_action_learn(table_id=1, priority=65111) learn.spec = [ nx.flow_mod_spec(src=nx.nx_learn_src_field(nx.NXM_NX_REG2), dst=nx.nx_learn_dst_match(nx.NXM_NX_REG2)), ] fms = nx.flow_mod_spec.new learn.spec.append( fms(load=nx.NXM_NX_REG0, src=nx.nx_learn_src_immediate.u32(None, 1))) learn.spec.append(fms(field=nx.NXM_NX_REG0, reserved=True)) msg.actions.append(learn) msg.actions.append(nx.nx_action_resubmit.resubmit_table(table=3)) event.connection.send(msg) #2. Sync Ack (Should be after sync) msg = nx.nx_flow_mod() msg.table_id = 2 msg.match.eth_type = pkt.ethernet.IP_TYPE msg.match.ip_proto = ipv4.TCP_PROTOCOL msg.match.tcp_flags = 0x12 msg.priority = 65002 msg.match.NXM_NX_REG0 = 1 # learn function for table 1 learn = nx.nx_action_learn(table_id=1, priority=65111) learn.spec = [ nx.flow_mod_spec(src=nx.nx_learn_src_field(nx.NXM_NX_REG2), dst=nx.nx_learn_dst_match(nx.NXM_NX_REG2)), ] fms = nx.flow_mod_spec.new learn.spec.append( fms(load=nx.NXM_NX_REG0, src=nx.nx_learn_src_immediate.u32(None, 2))) learn.spec.append(fms(field=nx.NXM_NX_REG0, reserved=True)) msg.actions.append(learn) msg.actions.append(nx.nx_action_resubmit.resubmit_table(table=3)) event.connection.send(msg) #3. Ack msg = nx.nx_flow_mod() msg.table_id = 2 msg.match.eth_type = pkt.ethernet.IP_TYPE msg.match.ip_proto = ipv4.TCP_PROTOCOL msg.match.tcp_flags = 0x010 msg.priority = 65003 msg.match.NXM_NX_REG0 = 2 # learn function for table 1 learn = nx.nx_action_learn(table_id=1, priority=65111) learn.spec = [ nx.flow_mod_spec(src=nx.nx_learn_src_field(nx.NXM_NX_REG2), dst=nx.nx_learn_dst_match(nx.NXM_NX_REG2)), ] fms = nx.flow_mod_spec.new learn.spec.append( fms(load=nx.NXM_NX_REG0, src=nx.nx_learn_src_immediate.u32(None, 3))) learn.spec.append(fms(field=nx.NXM_NX_REG0, reserved=True)) msg.actions.append(learn) msg.actions.append(nx.nx_action_resubmit.resubmit_table(table=3)) event.connection.send(msg) #4. Fin msg = nx.nx_flow_mod() msg.table_id = 2 msg.match.eth_type = pkt.ethernet.IP_TYPE msg.match.ip_proto = ipv4.TCP_PROTOCOL msg.match.tcp_flags = 0x010 msg.priority = 65003 msg.match.NXM_NX_REG0 = 3 # learn function for table 1 learn = nx.nx_action_learn(table_id=1, priority=65111) learn.spec = [ nx.flow_mod_spec(src=nx.nx_learn_src_field(nx.NXM_NX_REG2), dst=nx.nx_learn_dst_match(nx.NXM_NX_REG2)), ] fms = nx.flow_mod_spec.new learn.spec.append( fms(load=nx.NXM_NX_REG0, src=nx.nx_learn_src_immediate.u32(None, 4))) learn.spec.append(fms(field=nx.NXM_NX_REG0, reserved=True)) msg.actions.append(learn) msg.actions.append(nx.nx_action_resubmit.resubmit_table(table=3)) event.connection.send(msg) #5. Fin-Ack msg = nx.nx_flow_mod() msg.table_id = 2 msg.match.eth_type = pkt.ethernet.IP_TYPE msg.match.ip_proto = ipv4.TCP_PROTOCOL msg.match.tcp_flags = 0x010 msg.priority = 65003 msg.match.NXM_NX_REG0 = 4 # learn function for table 1 learn = nx.nx_action_learn(table_id=1, priority=65111) learn.spec = [ nx.flow_mod_spec(src=nx.nx_learn_src_field(nx.NXM_NX_REG2), dst=nx.nx_learn_dst_match(nx.NXM_NX_REG2)), ] fms = nx.flow_mod_spec.new learn.spec.append( fms(load=nx.NXM_NX_REG0, src=nx.nx_learn_src_immediate.u32(None, 5))) learn.spec.append(fms(field=nx.NXM_NX_REG0, reserved=True)) msg.actions.append(learn) msg.actions.append(nx.nx_action_resubmit.resubmit_table(table=3)) event.connection.send(msg) #7. Ack msg = nx.nx_flow_mod() msg.table_id = 2 msg.match.eth_type = pkt.ethernet.IP_TYPE msg.match.ip_proto = ipv4.TCP_PROTOCOL msg.match.tcp_flags = 0x010 msg.priority = 65003 msg.match.NXM_NX_REG0 = 5 # learn function for table 1 learn = nx.nx_action_learn(table_id=1, priority=65111) learn.spec = [ nx.flow_mod_spec(src=nx.nx_learn_src_field(nx.NXM_NX_REG2), dst=nx.nx_learn_dst_match(nx.NXM_NX_REG2)), ] fms = nx.flow_mod_spec.new learn.spec.append( fms(load=nx.NXM_NX_REG0, src=nx.nx_learn_src_immediate.u32(None, 6))) learn.spec.append(fms(field=nx.NXM_NX_REG0, reserved=True)) msg.actions.append(learn) msg.actions.append(nx.nx_action_resubmit.resubmit_table(table=3)) event.connection.send(msg) #8. RST msg = nx.nx_flow_mod() msg.table_id = 2 msg.match.eth_type = pkt.ethernet.IP_TYPE msg.match.ip_proto = ipv4.TCP_PROTOCOL msg.match.tcp_flags = 0x14 msg.priority = 65003 msg.actions.append(nx.nx_action_resubmit.resubmit_table(table=3)) event.connection.send(msg) #9. PSH-Ack msg = nx.nx_flow_mod() msg.table_id = 2 msg.match.eth_type = pkt.ethernet.IP_TYPE msg.match.ip_proto = ipv4.TCP_PROTOCOL msg.match.tcp_flags = 0x18 msg.priority = 65003 msg.actions.append(nx.nx_action_resubmit.resubmit_table(table=3)) event.connection.send(msg) #9. Ack msg = nx.nx_flow_mod() msg.table_id = 2 msg.match.eth_type = pkt.ethernet.IP_TYPE msg.match.ip_proto = ipv4.TCP_PROTOCOL msg.match.tcp_flags = 0x10 msg.priority = 65003 msg.actions.append(nx.nx_action_resubmit.resubmit_table(table=3)) event.connection.send(msg) #send to controller currently sending to the destination as no old state stored msg = nx.nx_flow_mod() msg.table_id = 2 msg.priority = 64999 msg.actions.append(nx.nx_reg_load(dst=nx.NXM_NX_REG1, value=int(1))) msg.actions.append(nx.nx_action_resubmit.resubmit_table(table=3)) event.connection.send(msg) log.info("Table 2 done") #Table 3 Rules: Forward the packet to the Destination msg = nx.nx_flow_mod() msg.table_id = 3 msg.match.eth_type = pkt.ethernet.IP_TYPE msg.match.ip_dst = "10.0.0.1" msg.priority = 65001 msg.actions.append(of.ofp_action_output(port=1)) event.connection.send(msg) msg = nx.nx_flow_mod() msg.table_id = 3 msg.match.eth_type = pkt.ethernet.IP_TYPE msg.match.ip_dst = "10.0.0.2" msg.priority = 65001 msg.actions.append(of.ofp_action_output(port=2)) event.connection.send(msg) msg = nx.nx_flow_mod() msg.table_id = 3 msg.match.eth_type = pkt.ethernet.IP_TYPE msg.match.ip_dst = "10.0.0.3" msg.priority = 65001 msg.actions.append(of.ofp_action_output(port=3)) event.connection.send(msg) #send to controller msg = nx.nx_flow_mod() msg.table_id = 3 msg.match.NXM_NX_REG1 = 1 msg.priority = 65005 msg.actions.append(of.ofp_action_output(port=of.OFPP_CONTROLLER)) event.connection.send(msg) log.info("Table 3 done") #Table 4 Rules msg = nx.nx_flow_mod() msg.table_id = 4 msg.actions.append(of.ofp_action_output(port=of.OFPP_FLOOD)) event.connection.send(msg) log.info("Table 4 done")
def set_hosts (self, host_data): """ Receive list of hosts This gets called with a list of dictionaries that each contain information about a host. Each time this is called, you get a complete list of all current hosts. Each entry looks something like this: {"ether" : "01:02:03:04:05:06", "ip" : "1.2.3.4", "attached_switch" : dpid, "attached_port" : portno}, In a datacenter, you might get this kind of information from a Cloud Management System. In our case, garnet's sync_hosts() sends us the list of Host entities in the "emulated" network garnet is managing. We receive it via the POX Messenger component and the messenger bot above. """ self.last_host_data = host_data for host in host_data: self.log.info("Got host: %s", " ".join("%s=%s" % kv for kv in sorted(host.items()))) host_e = str(host['ether']) switch_dpid = host['attached_switch'] switch_port = host['attached_port'] switch_name = self.graph.names[switch_dpid] self.hosts[host_e] = switch_dpid self.edge[switch_dpid] = switch_port if host_e in self.graph: self.graph.remove_node(host_e) # alter table info on attached switch # add host to networkX graph attached_switch = self.graph.names[switch_dpid] self.graph.add_edge(host_e, attached_switch) self.graph.add_edge(attached_switch, host_e) port_dict = {'ports': {attached_switch: switch_port}} self.graph.edge[host_e][attached_switch] = port_dict self.graph.edge[attached_switch][host_e] = port_dict core.openflow.sendToDPID(switch_dpid, nx_flow_mod_table_id()) # Enables multiple tables data = [] # construct command to remove VLAN and output to host fm = ofp_flow_mod_table_id( table_id = 0, match = of01.ofp_match(dl_dst=EthAddr(host_e)), command = of01.OFPFC_MODIFY, actions = [ofp_action_strip_vlan(), ofp_action_output(port=switch_port)]) data.append(fm.pack()) for dst_host, dst_switch_dpid in self.hosts.items(): if dst_host == host_e: continue if not self._connection_is_permitted(host_e, dst_host): # If we're not allowed to send to this host (or this host is not allowed to receive), tell our switch # to drop all traffic going to this host. self.log.info("MatchedDenyACE: src=%s dst=%s" % host_e, dst_host) fm = ofp_flow_mod_table_id( table_id = 0, command = of01.OFPFC_MODIFY, match = of01.ofp_match(dl_src=EthAddr(host_e), dl_dst=EthAddr(dst_host)), actions = None) data.append(fm.pack()) continue dst_switch_name = self.graph.names[dst_switch_dpid] #self.log.info(switch_name + ' ' + dst_switch_name) if switch_name == dst_switch_name: continue try: next_hop = nx.shortest_path(self.graph, source=switch_name, target=dst_switch_name)[1] except: continue shortest_path_port = self.graph[switch_name][next_hop]['ports'][switch_name] #self.log.info(str(host_e) + ' ' + str(dst_host)) #self.log.info(str(dst_switch_dpid) + ' ' + str(shortest_path_port)) # inform attached switch where other hosts are fm = ofp_flow_mod_table_id( table_id = 0, command = of01.OFPFC_MODIFY, match = of01.ofp_match(dl_src=EthAddr(host_e), dl_dst=EthAddr(dst_host)), actions = [ofp_action_set_vlan_vid(vlan_vid=dst_switch_dpid), ofp_action_output(port=shortest_path_port)]) data.append(fm.pack()) core.openflow.sendToDPID(dst_switch_dpid, nx_flow_mod_table_id()) # Enables multiple tables try: next_hop = nx.shortest_path(self.graph, source=dst_switch_name, target=switch_name)[1] except: continue shortest_path_port = self.graph[dst_switch_name][next_hop]['ports'][dst_switch_name] # inform other attached switches where this host is fm = ofp_flow_mod_table_id( table_id = 0, command = of01.OFPFC_MODIFY, match = of01.ofp_match(dl_src=EthAddr(dst_host), dl_dst=EthAddr(host_e)), actions = [ofp_action_set_vlan_vid(vlan_vid=switch_dpid), ofp_action_output(port=shortest_path_port)]) core.openflow.sendToDPID(dst_switch_dpid, fm.pack()) core.openflow.sendToDPID(switch_dpid, b''.join(data)) self.broadcast_paths()
def __init__(self, connection): self.connection = connection connection.addListeners(self) if (connection.eth_addr.toStr() == "00:00:00:00:00:01"): # Rules for switch s1 ! ''' Table id is a number for the the table of rules for each switch. Priority is for overlapping matches. Higher values are higher priority. in_port - If using a buffer_id, this is the associated input port. match - An ofp_match object. By default, this matches everything, so you should probably set some of its fields! ''' print "Preparing of rules" msg = nx.nx_flow_mod_table_id() connection.send(msg) #table 0 - Rules for IP :01 ''' Forward a packet to source if the port that is coming is the same as the input ''' msg = nx.nx_flow_mod() msg.table_id = 0 msg.priority = 1500 msg.match.of_eth_dst = "00:00:00:00:00:00" msg.match.of_eth_type = 0x86dd msg.match.of_in_port = 1 msg.actions.append(nx.nx_action_resubmit.resubmit_table(table=1)) self.connection.send(msg) ''' When a message comes to the Switch if has a rule for this IPv6 forward it to next port ''' msg = nx.nx_flow_mod() msg.table_id = 0 msg.priority = 1000 msg.match.of_eth_dst = "00:00:00:00:00:00" msg.match.of_eth_type = 0x86dd msg.match.nx_ipv6_dst = (IPAddr6("::1"), IPAddr6("::1")) msg.actions.append(of.ofp_action_output(port=1)) msg.actions.append(nx.nx_action_resubmit.resubmit_table(table=1)) self.connection.send(msg) ''' If you have no rule for this IP check table 1 for IP :02 ''' msg = nx.nx_flow_mod() msg.table_id = 0 msg.priority = 500 msg.match.of_eth_dst = "00:00:00:00:00:00" msg.match.of_eth_type = 0x86dd msg.actions.append(nx.nx_action_resubmit.resubmit_table(table=1)) self.connection.send(msg) #table 1 - Rules for IP :02 msg = nx.nx_flow_mod() msg.table_id = 1 msg.priority = 1000 msg.match.of_eth_dst = "00:00:00:00:00:00" msg.match.of_eth_type = 0x86dd msg.match.nx_ipv6_dst = (IPAddr6("::2"), IPAddr6("::2")) msg.actions.append(of.ofp_action_output(port=1)) self.connection.send(msg) msg = nx.nx_flow_mod() msg.table_id = 1 msg.priority = 1500 msg.match.of_eth_dst = "00:00:00:00:00:00" msg.match.of_eth_type = 0x86dd msg.match.of_in_port = 2 self.connection.send(msg) if (connection.eth_addr.toStr() == "00:00:00:00:00:02"): # Rules for switch s2 ! print "Preparing of rules" ''' The same Rules also for Switch 2 check the above comments.. ''' msg = nx.nx_flow_mod_table_id() connection.send(msg) #table 0 msg = nx.nx_flow_mod() msg.table_id = 0 msg.priority = 1500 msg.match.of_eth_dst = "00:00:00:00:00:00" msg.match.of_eth_type = 0x86dd msg.match.of_in_port = 1 msg.actions.append(nx.nx_action_resubmit.resubmit_table(table=1)) self.connection.send(msg) msg = nx.nx_flow_mod() msg.table_id = 0 msg.priority = 1000 msg.match.of_eth_dst = "00:00:00:00:00:00" msg.match.of_eth_type = 0x86dd msg.match.nx_ipv6_dst = (IPAddr6("::2"), IPAddr6("::2")) msg.actions.append(of.ofp_action_output(port=1)) msg.actions.append(nx.nx_action_resubmit.resubmit_table(table=1)) self.connection.send(msg) msg = nx.nx_flow_mod() msg.table_id = 0 msg.priority = 500 msg.match.of_eth_dst = "00:00:00:00:00:00" msg.match.of_eth_type = 0x86dd msg.actions.append(nx.nx_action_resubmit.resubmit_table(table=1)) self.connection.send(msg) #table 1 msg = nx.nx_flow_mod() msg.table_id = 1 msg.priority = 1000 msg.match.of_eth_dst = "00:00:00:00:00:00" msg.match.of_eth_type = 0x86dd msg.match.nx_ipv6_dst = (IPAddr6("::4"), IPAddr6("::4")) msg.actions.append(of.ofp_action_output(port=2)) self.connection.send(msg) msg = nx.nx_flow_mod() msg.table_id = 1 msg.priority = 1500 msg.match.of_eth_dst = "00:00:00:00:00:00" msg.match.of_eth_type = 0x86dd msg.match.of_in_port = 2 self.connection.send(msg)