Ejemplo n.º 1
0
def check_macsec_pkt(macsec_attr, test, ptf_port_id, exp_pkt, timeout=3):
    device, ptf_port = testutils.port_to_tuple(ptf_port_id)
    received_packets = []
    encrypt, send_sci, xpn_en, sci, an, sak, ssci, salt = macsec_attr
    end_time = time.time() + timeout
    while True:
        cur_time = time.time()
        if cur_time > end_time:
            break
        ret = testutils.dp_poll(
            test, device_number=device, port_number=ptf_port, timeout=end_time - cur_time, exp_pkt=None)
        if isinstance(ret, test.dataplane.PollFailure):
            break
        # If the packet isn't MACsec type
        pkt = scapy.Ether(ret.packet)
        if pkt[scapy.Ether].type != 0x88e5:
            continue
        received_packets.append(pkt)
    for i in range(len(received_packets)):
        pkt = received_packets[i]
        pn = 0
        pkt = decap_macsec_pkt(pkt, sci, an, sak, encrypt,
                               send_sci, pn, xpn_en, ssci, salt)
        if not pkt:
            continue
        received_packets[i] = pkt
        if exp_pkt.pkt_match(pkt):
            return
    fail_message = "Expect pkt \n{}\n{}\nBut received \n".format(
        exp_pkt, exp_pkt.exp_pkt.show(dump=True))
    for packet in received_packets:
        fail_message += "\n{}\n".format(packet.show(dump=True))
    return fail_message
Ejemplo n.º 2
0
 def ctc_send_packet(self, port_id, pkt, count=1):
     device, port = testutils.port_to_tuple(port_id)
     sendport = port + 1
     for n in range(count):
         testutils.pxr_send(self, sendport, str(pkt))
     time.sleep(2)
     testutils.pxr_getPacketBuffer(self)
     return
Ejemplo n.º 3
0
def check_macsec_pkt(test, ptf_port_id, exp_pkt, timeout=3):
    device, ptf_port = testutils.port_to_tuple(ptf_port_id)
    ret = testutils.dp_poll(test,
                            device_number=device,
                            port_number=ptf_port,
                            timeout=timeout,
                            exp_pkt=exp_pkt)
    if isinstance(ret, test.dataplane.PollSuccess):
        return
    else:
        return ret.format()
Ejemplo n.º 4
0
        def verify_packet_count(self, pkt, port_id):
            test = self.outer.ptfadapter
            device, port = testutils.port_to_tuple(port_id)
            logging.debug("Checking for pkt on device %d, port %d", device,
                          port)
            result = testutils.dp_poll(test,
                                       device_number=device,
                                       port_number=port,
                                       exp_pkt=pkt)
            if isinstance(result, test.dataplane.PollSuccess):
                return (1, result.packet)

            return (0, None)