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'] = {} # Turn on Nicira packet_ins msg = nx.nx_packet_in_format() event.connection.send(msg) msg = nx.nx_flow_mod() msg.actions.append(of.ofp_action_output(port=of.OFPP_CONTROLLER)) self.switches[event.dpid]['connection'].send(msg) #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 _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 _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'] = {} # Turn on Nicira packet_ins msg = nx.nx_packet_in_format() event.connection.send(msg) msg = nx.nx_flow_mod() msg.actions.append(of.ofp_action_output(port = of.OFPP_CONTROLLER)) self.switches[event.dpid]['connection'].send(msg) #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 _handle_ConnectionUp(self,event): print "connection up" #Tutorial(event.connection) event.connection.send(nx.nx_packet_in_format()) for m in self.matches: print "sending " self.sendMatch(m,event.connection)
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): # 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)