コード例 #1
0
    def generate_bddp_packet(self, switch_name, port):
        if self.topo_client.key_bddp is None:
            print("ERROR: cant encrypt lldp because key is not set")
            return

        ether = Ether(src=self.mac_address,
                      dst='ff:ff:ff:ff:ff:ff',
                      type=0x8999)
        lldp_chassis_id = lldp.LLDPDUChassisID(id=str.encode(switch_name))
        lldp_port_id = lldp.LLDPDUPortID(id=struct.pack(">H", port))
        lldp_timte_to_live = lldp.LLDPDUTimeToLive(ttl=6)
        lldp_end_of_lldp = lldp.LLDPDUEndOfLLDPDU()

        lldp_p = ether / lldp_chassis_id / lldp_port_id / lldp_timte_to_live / lldp_end_of_lldp
        nonce = os.urandom(12)
        aesgcm = AESGCM(self.topo_client.key_bddp)
        seq = struct.pack(">i", self.bddp_seq)
        ciphertext = aesgcm.encrypt(nonce, str(lldp_p)[14:], seq)

        self.bddp_seq = self.bddp_seq + 1
        #cpu header: q hat Laenge 8, w hat Laenge 2
        reason = struct.pack(">H", 60001)
        out_port = struct.pack(">H", port)
        zeros = struct.pack(">q", 0)
        timestamp1 = struct.pack('<H', 0)
        timestamp2 = struct.pack('<H', 0)
        timestamp3 = struct.pack('<H', 0)
        cpu_header = zeros + reason + out_port + timestamp1 + timestamp2 + timestamp3

        print('sending BDDP packet on port ' + str(port))
        return (cpu_header + str(ether) + nonce + seq + ciphertext)
コード例 #2
0
ファイル: controller.py プロジェクト: ahaWDY/HPDN
    def generate_lldp_packet(self, port):
        pkt = Ether(src='00:00:00:00:00:00', dst="ff:ff:ff:ff:ff:ff")
        lldp_chassis_id = lldp.LLDPDUChassisID(id=str.encode(self.sw.name))
        lldp_port_id = lldp.LLDPDUPortID(id=struct.pack(">H", port))
        lldp_time_to_live = lldp.LLDPDUTimeToLive(ttl=1)
        lldp_end_of_lldp = lldp.LLDPDUEndOfLLDPDU()

        pkt = pkt / lldp_chassis_id / lldp_port_id / lldp_time_to_live / lldp_end_of_lldp

        zeros = struct.pack(">q", 0)
        ingress_port = struct.pack(">H", port)
        type = struct.pack(">H", 5)
        header = zeros + ingress_port + type

        print "sending LLDP packet on port" + str(port)
        return (header + str(pkt))
コード例 #3
0
    def do_send_lldp_packet(self, line):
        [s0] = self.controller.switches
        port = int(line)

        pkt = Ether(src='00:00:00:00:00:00', dst='ff:ff:ff:ff:ff:ff')
        lldp_chassis_id = lldp.LLDPDUChassisID(id=str.encode(s0.name))
        lldp_port_id = lldp.LLDPDUPortID(id=struct.pack(">H", port))
        lldp_timte_to_live = lldp.LLDPDUTimeToLive(ttl=6)
        lldp_end_of_lldp = lldp.LLDPDUEndOfLLDPDU()

        pkt = pkt / lldp_chassis_id / lldp_port_id / lldp_timte_to_live / lldp_end_of_lldp
        #cpu header: q hat Laenge 8, w hat Laenge 2
        reason = struct.pack(">H", 4)
        out_port = struct.pack(">H", port)
        zeros = struct.pack(">q", 0)
        cpu_header = zeros + reason + out_port

        self.controller.send_packet_out(s0, cpu_header + str(pkt))
コード例 #4
0
    def generate_lldp_packet(self, switch_name, port):
        pkt = Ether(src=self.mac_address, dst='ff:ff:ff:ff:ff:ff')
        lldp_chassis_id = lldp.LLDPDUChassisID(id=str.encode(switch_name))
        lldp_port_id = lldp.LLDPDUPortID(id=struct.pack(">H", port))
        lldp_timte_to_live = lldp.LLDPDUTimeToLive(ttl=6)
        lldp_end_of_lldp = lldp.LLDPDUEndOfLLDPDU()

        pkt = pkt / lldp_chassis_id / lldp_port_id / lldp_timte_to_live / lldp_end_of_lldp
        #cpu header: q hat Laenge 8, w hat Laenge 2
        reason = struct.pack(">H", 60001)
        out_port = struct.pack(">H", port)
        zeros = struct.pack(">q", 0)
        timestamp1 = struct.pack('<H', 0)
        timestamp2 = struct.pack('<H', 0)
        timestamp3 = struct.pack('<H', 0)
        cpu_header = zeros + reason + out_port + timestamp1 + timestamp2 + timestamp3

        print('sending LLDP packet on port ' + str(port))
        return (cpu_header + str(pkt))
コード例 #5
0
ファイル: action.py プロジェクト: svinota/open-kilda
    def _encode(self, entry):
        entries = (lldp.LLDPDUChassisID(
            subtype=lldp.LLDPDUChassisID.SUBTYPE_MAC_ADDRESS,
            id=entry.chassis_id),
                   lldp.LLDPDUPortID(
                       subtype=lldp.LLDPDUPortID.SUBTYPE_LOCALLY_ASSIGNED,
                       id=entry.port_number),
                   lldp.LLDPDUTimeToLive(ttl=entry.time_to_live))
        if entry.port_description:
            entries = entries + (lldp.LLDPDUPortDescription(
                description=entry.port_description), )
        if entry.system_name:
            entries = entries + (lldp.LLDPDUSystemName(
                system_name=entry.system_name), )
        if entry.system_description:
            entries = entries + (lldp.LLDPDUSystemDescription(
                description=entry.system_description), )

        entries = entries + (lldp.LLDPDUEndOfLLDPDU(), )
        payload = functools.reduce(operator.truediv, entries)

        return Ether(src=entry.mac_address, dst=self.lldp_bcast_mac) / payload