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)
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)