def _generate_config_bpdu(self, flags): src_mac = self.ofport.hw_addr dst_mac = bpdu.BRIDGE_GROUP_ADDRESS length = (bpdu.bpdu._PACK_LEN + bpdu.ConfigurationBPDUs.PACK_LEN + llc.llc._PACK_LEN + llc.ControlFormatU._PACK_LEN) e = ethernet.ethernet(dst_mac, src_mac, length) l = llc.llc(llc.SAP_BPDU, llc.SAP_BPDU, llc.ControlFormatU()) b = bpdu.ConfigurationBPDUs( flags=flags, root_priority=self.port_priority.root_id.priority, root_mac_address=self.port_priority.root_id.mac_addr, root_path_cost=self.port_priority.root_path_cost + self.path_cost, bridge_priority=self.bridge_id.priority, bridge_mac_address=self.bridge_id.mac_addr, port_priority=self.port_id.priority, port_number=self.ofport.port_no, message_age=self.port_times.message_age + 1, max_age=self.port_times.max_age, hello_time=self.port_times.hello_time, forward_delay=self.port_times.forward_delay) pkt = packet.Packet() pkt.add_protocol(e) pkt.add_protocol(l) pkt.add_protocol(b) pkt.serialize() return pkt.data
class Test_ControlFormatI(unittest.TestCase): msg = llc.llc(llc.SAP_BPDU, llc.SAP_BPDU, llc.ControlFormatI()) def test_json(self): jsondict = self.msg.to_jsondict() msg = llc.llc.from_jsondict(jsondict['llc']) eq_(str(self.msg), str(msg))
def _generate_tcn_bpdu(self): src_mac = self.ofport.hw_addr dst_mac = bpdu.BRIDGE_GROUP_ADDRESS length = (bpdu.bpdu._PACK_LEN + bpdu.TopologyChangeNotificationBPDUs.PACK_LEN + llc.llc._PACK_LEN + llc.ControlFormatU._PACK_LEN) e = ethernet.ethernet(dst_mac, src_mac, length) l = llc.llc(llc.SAP_BPDU, llc.SAP_BPDU, llc.ControlFormatU()) b = bpdu.TopologyChangeNotificationBPDUs() pkt = packet.Packet() pkt.add_protocol(e) pkt.add_protocol(l) pkt.add_protocol(b) pkt.serialize() return pkt.data
class Test_ControlFormatU(Test_ControlFormatI): msg = llc.llc(llc.SAP_BPDU, llc.SAP_BPDU, llc.ControlFormatU())
def generate_bpdu(self, agreement=False): if agreement: b = self.last_prop_bpdu new_flags = b.flags | FLAG_BIT_AGRMNT b.flags = new_flags else: flags = FLAG_BIT_CLR ## role ## if (self.role is PORT_ROLE_ALTERNATE) or (self.role is PORT_ROLE_BACKUP): flags = flags | FLAG_BIT_ALT_BCK elif self.role is PORT_ROLE_ROOT: flags = flags | FLAG_BIT_ROOT elif self.role is PORT_ROLE_DESIGNATED: flags = flags | FLAG_BIT_DSG ## tc ## if self.topo_change: self.send_event(EventTopologyChange(self.dp)) flags = flags | FLAG_BIT_TC ## Proposal ## if self.proposing: flags = flags | FLAG_BIT_PROP ## Forwarding - Learning ## if self.state is PORT_STATE_LEARNING: flags = flags | FLAG_BIT_LRNG if self.state is PORT_STATE_FORWARDING: flags = flags | FLAG_BIT_FRWD b = bpdu.RstBPDUs( flags=flags, root_priority=self.priority.root_id.priority, root_mac_address=self.priority.root_id.mac_addr, root_system_id_extension=self.priority.root_id. system_id_extension, root_path_cost=self.priority.root_path_cost, bridge_priority=self.bridge_id.priority, bridge_mac_address=self.bridge_id.mac_addr, bridge_system_id_extension=self.bridge_id.system_id_extension, port_priority=self.port_id.priority, port_number=self.ofport.port_no, message_age=self.bridge_times.message_age, max_age=self.bridge_times.max_age, hello_time=self.bridge_times.hello_time, forward_delay=self.bridge_times.forward_delay) src_mac = self.ofport.hw_addr dst_mac = bpdu.BRIDGE_GROUP_ADDRESS length = (bpdu.bpdu._PACK_LEN + bpdu.ConfigurationBPDUs.PACK_LEN + bpdu.RstBPDUs.PACK_LEN + llc.llc._PACK_LEN + llc.ControlFormatU._PACK_LEN) e = ethernet.ethernet(dst_mac, src_mac, length) l = llc.llc(llc.SAP_BPDU, llc.SAP_BPDU, llc.ControlFormatU()) pkt = packet.Packet() pkt.add_protocol(e) pkt.add_protocol(l) pkt.add_protocol(b) pkt.serialize() return pkt.data