// callback void NetDeviceFace::receiveFromNetDevice(Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol, const Address& from, const Address& to, NetDevice::PacketType packetType) { NS_LOG_FUNCTION(device << p << protocol << from << to << packetType); Ptr<Packet> packet = p->Copy(); try { uint32_t type = Convert::getPacketType(p); if (type == ::ndn::tlv::Interest) { shared_ptr<const Interest> i = Convert::FromPacket<Interest>(packet); this->onReceiveInterest(*i); } else if (type == ::ndn::tlv::Data) { shared_ptr<const Data> d = Convert::FromPacket<Data>(packet); this->onReceiveData(*d); } else { NS_LOG_ERROR("Unsupported TLV packet"); } } catch (::ndn::tlv::Error&) { NS_LOG_ERROR("Unrecognized TLV packet"); } }
void PhyTxStatsCalculator::DlPhyTransmission (PhyTransmissionStatParameters params) { NS_LOG_FUNCTION (this << params.m_cellId << params.m_imsi << params.m_timestamp << params.m_rnti << params.m_layer << params.m_mcs << params.m_size << params.m_rv << params.m_ndi); NS_LOG_INFO ("Write DL Tx Phy Stats in " << GetDlTxOutputFilename ().c_str ()); std::ofstream outFile; if ( m_dlTxFirstWrite == true ) { outFile.open (GetDlOutputFilename ().c_str ()); if (!outFile.is_open ()) { NS_LOG_ERROR ("Can't open file " << GetDlTxOutputFilename ().c_str ()); return; } m_dlTxFirstWrite = false; //outFile << "% time\tcellId\tIMSI\tRNTI\tlayer\tmcs\tsize\trv\tndi"; // txMode is not available at dl tx side outFile << "% time\tcellId\tIMSI\tRNTI\tlayer\tmcs\tsize\trv\tndi"; outFile << std::endl; } else { outFile.open (GetDlTxOutputFilename ().c_str (), std::ios_base::app); if (!outFile.is_open ()) { NS_LOG_ERROR ("Can't open file " << GetDlTxOutputFilename ().c_str ()); return; } } // outFile << Simulator::Now ().GetNanoSeconds () / (double) 1e9 << "\t"; outFile << params.m_timestamp << "\t"; outFile << (uint32_t) params.m_cellId << "\t"; outFile << params.m_imsi << "\t"; outFile << params.m_rnti << "\t"; //outFile << (uint32_t) params.m_txMode << "\t"; // txMode is not available at dl tx side outFile << (uint32_t) params.m_layer << "\t"; outFile << (uint32_t) params.m_mcs << "\t"; outFile << params.m_size << "\t"; outFile << (uint32_t) params.m_rv << "\t"; outFile << (uint32_t) params.m_ndi << std::endl; outFile.close (); }
bool CsmaChannel::TransmitEnd () { NS_LOG_FUNCTION (this << m_currentPkt << m_currentSrc); NS_LOG_INFO ("UID is " << m_currentPkt->GetUid () << ")"); NS_ASSERT (m_state == TRANSMITTING); m_state = PROPAGATING; bool retVal = true; if (!IsActive (m_currentSrc)) { NS_LOG_ERROR ("CsmaChannel::TransmitEnd(): Seclected source was detached before the end of the transmission"); retVal = false; } NS_LOG_LOGIC ("Schedule event in " << m_delay.GetSeconds () << " sec"); NS_LOG_LOGIC ("Receive"); std::vector<CsmaDeviceRec>::iterator it; uint32_t devId = 0; for (it = m_deviceList.begin (); it < m_deviceList.end (); it++) { if (it->IsActive ()) { // schedule reception events Simulator::ScheduleWithContext (it->devicePtr->GetNode ()->GetId (), m_delay, &CsmaNetDevice::Receive, it->devicePtr, m_currentPkt->Copy (), m_deviceList[m_currentSrc].devicePtr); } devId++; } // also schedule for the tx side to go back to IDLE Simulator::Schedule (m_delay, &CsmaChannel::PropagationCompleteEvent, this); return retVal; }
void L2RateTracer::InstallAll(const std::string& file, Time averagingPeriod /* = Seconds (0.5)*/) { std::list<Ptr<L2RateTracer>> tracers; std::shared_ptr<std::ostream> outputStream; if (file != "-") { std::shared_ptr<std::ofstream> os(new std::ofstream()); os->open(file.c_str(), std::ios_base::out | std::ios_base::trunc); if (!os->is_open()) { NS_LOG_ERROR("File " << file << " cannot be opened for writing. Tracing disabled"); return; } outputStream = os; } else { outputStream = std::shared_ptr<std::ostream>(&std::cout, std::bind([]{})); } for (NodeList::Iterator node = NodeList::Begin(); node != NodeList::End(); node++) { NS_LOG_DEBUG("Node: " << boost::lexical_cast<std::string>((*node)->GetId())); Ptr<L2RateTracer> trace = Create<L2RateTracer>(outputStream, *node); trace->SetAveragingPeriod(averagingPeriod); tracers.push_back(trace); } if (tracers.size() > 0) { // *m_l3RateTrace << "# "; // not necessary for R's read.table tracers.front()->PrintHeader(*outputStream); *outputStream << "\n"; } g_tracers.push_back(std::make_tuple(outputStream, tracers)); }
bool CsmaChannel::TransmitStart (Ptr<Packet> p, uint32_t srcId) { NS_LOG_FUNCTION (this << p << srcId); NS_LOG_INFO ("UID is " << p->GetUid () << ")"); if (m_state != IDLE) { NS_LOG_WARN ("CsmaChannel::TransmitStart(): State is not IDLE"); return false; } if (!IsActive (srcId)) { NS_LOG_ERROR ("CsmaChannel::TransmitStart(): Seclected source is not currently attached to network"); return false; } NS_LOG_LOGIC ("switch to TRANSMITTING"); m_currentPkt = p; m_currentSrc = srcId; m_state = TRANSMITTING; return true; }
int main(int argc, char* argv[]) { ns_nfm_ret_t ret; ns_log_init(NS_LOG_COLOR | NS_LOG_CONSOLE); ns_log_lvl_set(NS_LOG_LVL_INFO); unsigned int i, k, t, min, max; unsigned int slot, netmod, iface, nm_intfs; uint32_t nm_mask; uint8_t nm_type; const char *nm_name; int c; while ((c = getopt_long(argc, argv, "l:d:h", __long_options, NULL)) != -1) { switch (c) { case 'l': ns_log_lvl_set((unsigned int)strtoul(optarg,0,0)); break; case 'h': default: print_usage(argv[0]); } } if (optind != argc) print_usage(argv[0]); ret = nfm_get_nfes_present(&k); CKRET(ret, "Error getting # of NFEs present"); printf("%u NFEs present\n", k); ret = nfm_get_nmsbs_present(&k); CKRET(ret, "Error getting # of NMSBs present"); printf("%u NMSBs present\n", k); if ( k < 1 ) { // No NMSB: geryon by now min = max = 1; ret = nfm_get_external_min_port(&min); CKRET(ret, "Error getting external minimum port"); ret = nfm_get_external_max_port(&max); CKRET(ret, "Error getting external maximum port"); printf("Port list\n"); printf("%16s%16s\n", "Port", "Hardware ID"); for (i = min; i <= max; i++) { ret = nfm_get_internal_port_from_external(i, &k); CKRET(ret, "Error converting external port # to internal"); printf("%16u%16u\n", i, k); /* sanity check */ ret = nfm_get_external_port_from_internal(k, &t); CKRET(ret, "Error converting internal port # to external"); if (t != i) NS_LOG_ERROR("Error conversion ext -> int -> ext " "produced %u -> %u -> %u", i, k, t); } } else { // NMSB: cayenne ret = nfm_get_netmods_present(&nm_mask); CKRET(ret, "Error getting # of netmods present"); ret = nfm_get_min_netmod(&min); CKRET(ret, "Error getting minimum netmod"); ret = nfm_get_max_netmod(&max); CKRET(ret, "Error getting maximum netmod"); /* Enumerate the Installed Netmods */ printf("netmods present (mask=%#x, %u - %u):\n", nm_mask, min, max); printf("%16s%16s%16s%16s\n", "Netmod", "Slot ID", "Netmod Type", "# Interfaces"); while (1) { slot = ffs(nm_mask); if (!slot) break; slot = slot - 1; /* ffs() count bits starting at 1. We don't */ nm_mask &= ~(1 << slot); ret = nfm_get_nmsb_attached_card(slot, &nm_type); CKRET(ret, "Error getting card type"); ret = nfm_get_nmsb_card_intfs(slot, &nm_intfs); CKRET(ret, "Error getting number of interfaces"); ret = nfm_get_nmsb_card_name(slot, &nm_name); CKRET(ret, "Error getting card name"); printf("%16s%16u%16u%16u\n", nm_name, slot, nm_type, nm_intfs); } printf("\n"); /* Enumerate the ports */ ret = nfm_get_external_min_port(&min); CKRET(ret, "Error getting external minimum port"); ret = nfm_get_external_max_port(&max); CKRET(ret, "Error getting external maximum port"); printf("Port list\n"); printf("%16s%16s%16s%16s\n", "Port", "Hardware ID", "Netmod", "NM Interface"); for (i = min; i <= max; i++) { ret = nfm_get_internal_port_from_external(i, &k); CKRET(ret, "Error converting external port # to internal"); ret = nfm_get_slot_from_external(i, &netmod, &iface); CKRET(ret, "Error converting external port # to netmod pair"); ret = nfm_get_nmsb_card_name(netmod, &nm_name); CKRET(ret, "Error getting card name"); printf("%16u%16u%16s%16u\n", i, k, nm_name, iface); /* sanity check */ ret = nfm_get_external_port_from_internal(k, &t); CKRET(ret, "Error converting internal port # to external"); if (t != i) NS_LOG_ERROR("Error conversion ext -> int -> ext " "produced %u -> %u -> %u", i, k, t); } } printf("\n"); return 0; }