/* This function is invoked by a node with hop count = 1.
 * This function creates an Path Establishment Answer packet and, using other
 * functions it sends
 * the packet back.
 */
void
SunIPRoutingNode::answerPath(const Packet *p_old)
{
	if (STACK_TRACE)
		cout << "> answerPath()" << endl;
	// This node is a node with hop count = 1. Checks anyway for errors.
	// The packet p_old is removed by the method that invokes this one.
	if (this->getNumberOfHopToSink() == 1) {
		Packet *p_answer = Packet::alloc();
		this->initPktPathEstAnswer(p_answer, p_old);
		hdr_cmn *ch_answer = HDR_CMN(p_answer);
		hdr_uwip *iph = HDR_UWIP(p_answer);
		hdr_sun_path_est *hpest = HDR_SUN_PATH_EST(p_answer);
		if (printDebug_ > 10)
			cout << "@" << Scheduler::instance().clock()
				 << " -> N: " << this->printIP(ipAddr_)
				 << " - CP: " << ch_answer->uid()
				 << " - Answer Path sent. Hop Count: "
				 << (hpest->list_of_hops_length() + 1)
				 << " (destination: " << printIP(iph->daddr()) << ")." << endl;
		number_of_pathestablishment_++;
		if (trace_)
			this->tracePacket(p_answer, "SEND_PTH");
		sendDown(p_answer, this->getDelay(period_status_));
		return;
	} else {
		return;
	}
} /* SunIPRoutingNode::answerPath */
LONGBOW_TEST_CASE(Dictionary, component_Codec_Tlv_Downcall_Read_Raw)
{
    TestData *data = longBowTestCase_GetClipBoardData(testCase);
    TransportMessage *tm = trafficTools_CreateTransportMessageWithDictionaryRaw(data->mock->connection,
                                                                                CCNxTlvDictionary_SchemaVersion_V1);
    TransportMessage *test_tm = sendDown(data, tm);
    PARCBuffer *buffer = ccnxWireFormatMessage_GetWireFormatBuffer(transportMessage_GetDictionary(test_tm));
    assertNotNull(buffer, "Output of codec did not have a raw format message");
    transportMessage_Destroy(&test_tm);
}
/**
 * control message should be passed through
 */
LONGBOW_TEST_CASE(Dictionary, component_Codec_Tlv_Downcall_Read_Control)
{
    TestData *data = longBowTestCase_GetClipBoardData(testCase);
    TransportMessage *tm = trafficTools_CreateTransportMessageWithDictionaryControl(data->mock->connection,
                                                                                    CCNxTlvDictionary_SchemaVersion_V1);
    TransportMessage *test_tm = sendDown(data, tm);
    PARCJSON *json = ccnxControlFacade_GetJson(transportMessage_GetDictionary(test_tm));
    assertNotNull(json, "Output of codec did not have a control message");
    transportMessage_Destroy(&test_tm);
}
/**
 * Makes sure an interest going down the stack gets encoded.  Does not test
 * the actual wire format -- that's the job of the tlv unit tests.
 */
LONGBOW_TEST_CASE(Dictionary, component_Codec_Tlv_Downcall_Read_Interest)
{
    TestData *data = longBowTestCase_GetClipBoardData(testCase);
    TransportMessage *tm = trafficTools_CreateTransportMessageWithDictionaryInterest(data->mock->connection, CCNxTlvDictionary_SchemaVersion_V1);
    TransportMessage *test_tm = sendDown(data, tm);
    CCNxCodecNetworkBufferIoVec *vec =
        ccnxTlvDictionary_GetIoVec(transportMessage_GetDictionary(test_tm), CCNxCodecSchemaV1TlvDictionary_HeadersFastArray_WireFormat);
    assertNotNull(vec, "Output of coded did not have a raw format message");
    transportMessage_Destroy(&test_tm);
}
void
UWMllModule::recv(Packet *p, int idSrc)
{
	hdr_cmn *ch = HDR_CMN(p);
	if (ch->direction() == hdr_cmn::UP) {
		sendUp(p);
	} else {
		ch->direction() = hdr_cmn::DOWN;
		sendDown(p);
	}
}
void
UwCbrModule::sendPkt()
{
	double delay = 0;
	Packet *p = Packet::alloc();
	this->initPkt(p);
	hdr_cmn *ch = hdr_cmn::access(p);
	hdr_uwcbr *uwcbrh = HDR_UWCBR(p);
	if (debug_ > 10)
		printf("CbrModule(%d)::sendPkt, send a pkt (%d) with sn: %d\n",
				getId(),
				ch->uid(),
				uwcbrh->sn());
	sendDown(p, delay);
}
/* This function receives a Path Establishment Answer Packet and checks
 * if the IP of the current node is in the list.
 * If no it drops the packet, otherwise it sends to the previous node the
 * packet,
 * and adds the information about the route in its the routing table.
 * Returns 0 if it drops the packet, 1 if it sends back the packet.
 */
void
SunIPRoutingNode::sendRouteBack(Packet *p)
{
	if (STACK_TRACE)
		cout << "> sendRouteBack()" << endl;
	hdr_cmn *ch = HDR_CMN(p);
	hdr_uwip *iph = HDR_UWIP(p);
	hdr_sun_path_est *hpest = HDR_SUN_PATH_EST(p);

	if (hpest->ptype() ==
			PATH_ANSWER) { // This function processes only PATH_ANSWER packets
		if (hpest->list_of_hops_length() == 0) {
			drop(p, 1, DROP_PATH_ESTABLISHMENT_ANSWER_PACKET_GARBAGE);
			return;
		} else {
			short j_ = hpest->pointer();
			if (hpest->list_of_hops()[j_] ==
					ipAddr_) { // The current node is the right next hop.
				// Update the hop table of the current node only if the node
				// receives a new best path or it doesn't have any path.
				/* The number of hops from the node to the sink are:
				 * list_of_hops_length - 1 + pointer + 1 = list_of_hops_length -
				 * pointer
				 */
				if (metrics_ == HOPCOUNT) {
					if (((hpest->list_of_hops_length() - hpest->pointer()) <=
								this->getNumberOfHopToSink()) ||
							(this->getNumberOfHopToSink() ==
									0)) { // Attention: the pointer is a
										  // decreasing value.
						// Reset of the routing information.
						this->clearHops();
						this->setNumberOfHopToSink(0);
						// Update the routing table of the current node.
						for (int i = j_ + 1, w = 0;
								i < hpest->list_of_hops_length();
								i++, w++) {
							hop_table[w] = hpest->list_of_hops()[i];
						}
						hop_table_length = hpest->list_of_hops_length() -
								hpest->pointer() - 1;
						this->setNumberOfHopToSink(hop_table_length + 1);
						sink_associated = hpest->sinkAssociated();
						rmhopTableTmr_.resched(timer_route_validity_);
						ack_warnings_counter_ = 0;
						ack_error_state = false;
					}
				} else if (metrics_ == SNR) {
					double tmp_ = hpest->quality();
					if (this->isZero(quality_link) || (quality_link < tmp_) ||
							(this->getNumberOfHopToSink() == 0)) {
						// Reset of the routing information.
						this->clearHops();
						this->setNumberOfHopToSink(0);
						// Update the routing table of the current node.
						for (int i = j_ + 1, w = 0;
								i < hpest->list_of_hops_length();
								i++, w++) {
							hop_table[w] = hpest->list_of_hops()[i];
						}
						hop_table_length = hpest->list_of_hops_length() -
								hpest->pointer() - 1;
						this->setNumberOfHopToSink(hop_table_length + 1);
						quality_link = tmp_;
						sink_associated = hpest->sinkAssociated();
						rmhopTableTmr_.resched(timer_route_validity_);
						ack_warnings_counter_ = 0;
						ack_error_state = false;
					}
				} else if (metrics_ == LESSCONGESTED) {
					double tmp_ =
							hpest->quality() / hpest->list_of_hops_length();
					if ((!this->isZero(quality_link) &&
								(quality_link > tmp_)) ||
							(this->getNumberOfHopToSink() == 0)) {
						// Reset of the routing information.
						this->clearHops();
						this->setNumberOfHopToSink(0);
						// Update the routing table of the current node.
						for (int i = j_ + 1, w = 0;
								i < hpest->list_of_hops_length();
								i++, w++) {
							hop_table[w] = hpest->list_of_hops()[i];
						}
						hop_table_length = hpest->list_of_hops_length() -
								hpest->pointer() - 1;
						this->setNumberOfHopToSink(hop_table_length + 1);
						quality_link = tmp_;
						sink_associated = hpest->sinkAssociated();
						rmhopTableTmr_.resched(timer_route_validity_);
						ack_warnings_counter_ = 0;
						ack_error_state = false;
					}
				}
				// Update the information in the Path Establishment Answer
				// packet.
				hpest->pointer()--;
				if (hpest->pointer() < 0) { // The list is over, the next hop
											// will be the destination.
					ch->next_hop() = iph->daddr();
					ch->prev_hop_ = ipAddr_;
				} else { // Look in the hop list for the next hop.
					ch->next_hop() = hpest->list_of_hops()[hpest->pointer()];
					ch->prev_hop_ = ipAddr_;
				}
				if (printDebug_ > 10)
					cout << "@" << Scheduler::instance().clock()
						 << " -> N: " << this->printIP(ipAddr_)
						 << " - CP: " << ch->uid()
						 << " - Send Answer Path reply. Next hop: "
						 << printIP(ch->next_hop())
						 << " (destination: " << printIP(iph->saddr()) << ")."
						 << endl;
				number_of_pathestablishment_++;
				if (trace_)
					this->tracePacket(p, "FRWD_PTH");
				sendDown(p, this->getDelay(period_status_));
				return;
			} else {
				drop(p, 1, DROP_PATH_ESTABLISHMENT_ANSWER_PACKET_GARBAGE);
				return;
			}
		}
	} else {
		Packet::free(p);
		return;
	}
} /* SunIPRoutingNode::sendRouteBack */
Beispiel #8
0
	// callback when pkt recved from up to down
	virtual size_t onFromUp(APassDataType type, const char *data, size_t size, bool force)
	{
		return sendDown(type, data, size, force);
	}