예제 #1
0
파일: grpc_server.py 프로젝트: p4vbox/vIFC
def sniffer_thread():
    global packetLim

    sniffer_instance = Sniffer(ServerConfig.PACKETIN_IFACE, 1500)

    newPacketIn = PacketInStruct()
    c_packet_id = 0

    print "Sniffer Thread Started"

    while True:
        pack_data = sniffer_instance.recv_packet_in()
        if (pack_data != False) and pack_data[0] >= 0 and pack_data[0] < len(
                packetLim) and (not packetLim[pack_data[0]]):
            packetLim[pack_data[0]] = True

            newPacketIn = PacketInStruct()
            newPacketIn.packetInResponse = p4runtime_pb2.StreamMessageResponse(
            )
            newPacketIn.packetInResponse.packet.payload = pack_data[2]
            newPacketIn.metadata = newPacketIn.packetInResponse.packet.metadata.add(
            )
            newPacketIn.metadata.metadata_id = pack_data[0]
            newPacketIn.metadata.value = pack_data[1]
            newPacketIn.packet_id = c_packet_id

            c_packet_id = c_packet_id + 1

            print "EXPT: Packet-in (%d): interface => server %.9f" % (
                c_packet_id, time.time())
            ConnectionArray.sendPacketInToBuffer(newPacketIn)
예제 #2
0
def sniffer_thread():
    sniffer_instance = Sniffer(ServerConfig.PACKETIN_IFACE, 1500)

    newPacketIn = PacketInStruct()

    print "Sniffer Thread Started"

    while True:
        pack_data = sniffer_instance.recv_packet_in()
        if pack_data is not False and pack_data[
                0] < 4:  #TODO: Remover "and pack_data[0] < 4", esta aqui para nao capturar outros pacotes na interface de teste
            newPacketIn.packetInResponse = p4runtime_pb2.StreamMessageResponse(
            )
            newPacketIn.packetInResponse.packet.payload = pack_data[2]
            newPacketIn.metadata = newPacketIn.packetInResponse.packet.metadata.add(
            )
            newPacketIn.metadata.metadata_id = pack_data[0]
            newPacketIn.metadata.value = pack_data[1]

            print "Packet-in: interface => server %.9f" % time.time()
            ConnectionArray.sendPacketInToBuffer(newPacketIn)