def create_discovery_packet(self, dpid, port_num, port_addr): """ Build discovery packet """ chassis_id = pkt.chassis_id(subtype=pkt.chassis_id.SUB_LOCAL) chassis_id.id = bytes('dpid:' + hex(long(dpid))[2:-1]) # Maybe this should be a MAC. But a MAC of what? Local port, maybe? port_id = pkt.port_id(subtype=pkt.port_id.SUB_PORT, id=str(port_num)) ttl = pkt.ttl(ttl=self._ttl) sysdesc = pkt.system_description() sysdesc.payload = bytes('dpid:' + hex(long(dpid))[2:-1]) discovery_packet = pkt.lldp() discovery_packet.tlvs.append(chassis_id) discovery_packet.tlvs.append(port_id) discovery_packet.tlvs.append(ttl) discovery_packet.tlvs.append(sysdesc) discovery_packet.tlvs.append(pkt.end_tlv()) eth = pkt.ethernet(type=pkt.ethernet.LLDP_TYPE) eth.src = port_addr eth.dst = pkt.ETHERNET.NDP_MULTICAST eth.payload = discovery_packet po = of.ofp_packet_out(action=of.ofp_action_output(port=port_num)) po.data = eth.pack() return po.pack()
def create_discovery_packet (self, dpid, port_num, port_addr): """ Build discovery packet """ chassis_id = pkt.chassis_id(subtype=pkt.chassis_id.SUB_LOCAL) chassis_id.id = bytes('dpid:' + hex(long(dpid))[2:-1]) # Maybe this should be a MAC. But a MAC of what? Local port, maybe? port_id = pkt.port_id(subtype=pkt.port_id.SUB_PORT, id=str(port_num)) ttl = pkt.ttl(ttl = self._ttl) sysdesc = pkt.system_description() sysdesc.payload = bytes('dpid:' + hex(long(dpid))[2:-1]) discovery_packet = pkt.lldp() discovery_packet.tlvs.append(chassis_id) discovery_packet.tlvs.append(port_id) discovery_packet.tlvs.append(ttl) discovery_packet.tlvs.append(sysdesc) discovery_packet.tlvs.append(pkt.end_tlv()) eth = pkt.ethernet(type=pkt.ethernet.LLDP_TYPE) eth.src = port_addr eth.dst = pkt.ETHERNET.NDP_MULTICAST eth.payload = discovery_packet po = of.ofp_packet_out(action = of.ofp_action_output(port=port_num)) po.data = eth.pack() return po.pack()
def install_flow(self, con_or_dpid, priority=None): if priority is None: priority = self._flow_priority if isinstance(con_or_dpid, (int, long)): con = core.openflow.connections.get(con_or_dpid) if con is None: log.warn("Can't install flow for %s", dpid_to_str(con_or_dpid)) return False else: con = con_or_dpid match = of.ofp_match(dl_type=pkt.ethernet.LLDP_TYPE, dl_dst=pkt.ETHERNET.NDP_MULTICAST) msg = of.ofp_flow_mod() msg.priority = priority msg.match = match msg.actions.append(of.ofp_action_output(port=of.OFPP_CONTROLLER)) con.send(msg) return True
def install_flow (self, con_or_dpid, priority = None): if priority is None: priority = self._flow_priority if isinstance(con_or_dpid, (int,long)): con = core.openflow.connections.get(con_or_dpid) if con is None: log.warn("Can't install flow for %s", dpid_to_str(con_or_dpid)) return False else: con = con_or_dpid match = of.ofp_match(dl_type = pkt.ethernet.LLDP_TYPE, dl_dst = pkt.ETHERNET.NDP_MULTICAST) msg = of.ofp_flow_mod() msg.priority = priority msg.match = match msg.actions.append(of.ofp_action_output(port = of.OFPP_CONTROLLER)) con.send(msg) return True