int receive(int port_num, const char *buffer, int len) { static int pkt_id = 0; auto packet = new_packet_ptr(port_num, pkt_id++, len, PacketBuffer(2048, buffer, len)); ELOGGER->packet_in(*packet); input_buffer.push_front(std::move(packet)); return 0; }
PacketBuffer Ethernet::makePacket() const { int size = EthernetSize; if( header_.protocol == ethernetProtocol::k_8021q ) size += Dot1QSize; uint8_t buff[size]; *((EthernetHeader*)buff) = header_; if( header_.protocol == ethernetProtocol::k_8021q ) *((VlanTag*)(buff+EthernetSize)) = vlanTag_; return PacketBuffer( buff, size ); }
PacketBuffer IPv6Address::makePacket( ) const { return PacketBuffer( address_ ); }
int ConnectorInterface::ReserveThreadPacketBuffer() { #if BEHAVIAC_COMPILER_MSVC uint32_t bufferIndex = (uint32_t)(uint64_t)TlsGetValue(t_packetBufferIndex); #else uint32_t bufferIndex = t_packetBufferIndex; #endif //THREAD_ID_TYPE id = behaviac::GetTID(); //BEHAVIAC_LOGINFO("ReserveThreadPacketBuffer:%d thread %d\n", bufferIndex, id); //bufferIndex initially is 0 if (bufferIndex <= 0) { int retIndex(-2); ScopedLock lock(m_packetBuffersLock); // NOTE: This is quite naive attempt to make sure that main thread queue // is the last one (rely on the fact that it's most likely to be the first // one trying to send message). This means EndFrame event should be sent after // memory operations from that frame. // (doesn't matter in SEQUENTIAL mode). for (int i = m_maxTracedThreads - 1; i >= 0; --i) { if (!m_packetBuffers[i]) { ScopedInt_t scopedInt(&gs_threadFlag); m_packetBuffers[i] = BEHAVIAC_NEW PacketBuffer(this); } if (m_packetBuffers[i]) { if (m_packetBuffers[i]->m_free) { m_packetBuffers[i]->m_free = false; retIndex = i; break; } } } if (retIndex > 0) { #if BEHAVIAC_COMPILER_MSVC TlsSetValue(t_packetBufferIndex, (PVOID)(uint64_t)retIndex); #else t_packetBufferIndex = retIndex; #endif } else { Log("behaviac: Couldn't reserve packet buffer, too many active threads.\n"); BEHAVIAC_ASSERT(false); } bufferIndex = retIndex; //BEHAVIAC_LOGINFO("ReserveThreadPacketBuffer:%d thread %d\n", bufferIndex, id); } return bufferIndex; }
Packet Packet::make_new(PHVSourceIface *phv_source) { return Packet(0, 0, 0, 0, 0, PacketBuffer(), phv_source); }