Exemplo n.º 1
0
    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
Exemplo n.º 2
0
    def setUp(self):
        self.protocol_id = bpdu.PROTOCOL_IDENTIFIER
        self.version_id = bpdu.ConfigurationBPDUs.VERSION_ID
        self.bpdu_type = bpdu.ConfigurationBPDUs.BPDU_TYPE
        self.flags = 0b00000001
        self.root_priority = 4096
        self.root_system_id_extension = 1
        self.root_mac_address = '12:34:56:78:9a:bc'
        self.root_path_cost = 2
        self.bridge_priority = 8192
        self.bridge_system_id_extension = 3
        self.bridge_mac_address = 'aa:aa:aa:aa:aa:aa'
        self.port_priority = 16
        self.port_number = 4
        self.message_age = 5
        self.max_age = 6
        self.hello_time = 7
        self.forward_delay = 8

        self.msg = bpdu.ConfigurationBPDUs(
            flags=self.flags,
            root_priority=self.root_priority,
            root_system_id_extension=self.root_system_id_extension,
            root_mac_address=self.root_mac_address,
            root_path_cost=self.root_path_cost,
            bridge_priority=self.bridge_priority,
            bridge_system_id_extension=self.bridge_system_id_extension,
            bridge_mac_address=self.bridge_mac_address,
            port_priority=self.port_priority,
            port_number=self.port_number,
            message_age=self.message_age,
            max_age=self.max_age,
            hello_time=self.hello_time,
            forward_delay=self.forward_delay)

        self.fmt = (bpdu.bpdu._PACK_STR +
                    bpdu.ConfigurationBPDUs._PACK_STR[1:])
        self.buf = struct.pack(
            self.fmt, self.protocol_id, self.version_id, self.bpdu_type,
            self.flags,
            bpdu.ConfigurationBPDUs.encode_bridge_id(
                self.root_priority, self.root_system_id_extension,
                self.root_mac_address), self.root_path_cost,
            bpdu.ConfigurationBPDUs.encode_bridge_id(
                self.bridge_priority, self.bridge_system_id_extension,
                self.bridge_mac_address),
            bpdu.ConfigurationBPDUs.encode_port_id(self.port_priority,
                                                   self.port_number),
            bpdu.ConfigurationBPDUs._encode_timer(self.message_age),
            bpdu.ConfigurationBPDUs._encode_timer(self.max_age),
            bpdu.ConfigurationBPDUs._encode_timer(self.hello_time),
            bpdu.ConfigurationBPDUs._encode_timer(self.forward_delay))