Exemplo n.º 1
0
/**
 * Asks for the capabilities of all local Link SAPs.
 *
 * @param in The input message.
 * @param out The output message.
 * @return Always false, because it does not send any response directly.
 */
bool service_management::link_capability_discover_request(meta_message_ptr &in,
														  meta_message_ptr &out)
{
	// Asks for local Link SAPs capabilities
	ODTONE_LOG(1, "(mism) gathering information about local Link SAPs capabilities");

	*out << mih::request(mih::request::capability_discover);
	out->tid(in->tid());
	out->destination(in->source());

	// Check if the Link SAP is still active
	uint16 fails = _link_abook.fail(out->destination().to_string());
	if(fails > kConf_MIHF_Link_Delete_Value) {
		mih::octet_string dst = out->destination().to_string();
		_link_abook.inactive(dst);

		// Update MIHF capabilities
		utils::update_local_capabilities(_abook, _link_abook, _user_abook);
	}
	else {
		ODTONE_LOG(1, "(mics) forwarding Link_Capability_Discover.request to ",
			out->destination().to_string());
		utils::forward_request(out, _lpool, _transmit);
	}

	return false;
}
Exemplo n.º 2
0
/**
 * Check if there's a handler for this message and call it, else
 * discard message.
 *
 * @param in The input message.
 * @param out The output message.
 */
bool sac_process_message(meta_message_ptr& in, meta_message_ptr& out)
{
	// discard messages that this MIHF broadcasted to itself
	// discard messages that are not destined to this MIHF or if
	// multicast messages are not supported
	if(in->source() == mihfid) {
		ODTONE_LOG(1, "(sac) Discarding message! Reason: ",
					  "message was broadcasted to itself");
		return false;
	}

	if(!utils::this_mihf_is_destination(in) && !utils::is_multicast(in)) {
		ODTONE_LOG(1, "(sac) Discarding message! Reason: ",
					  "this is not the message destination");
		return false;
	}

	/** __no__ authentication at this point */

	uint mid = in->mid();

	//
	// no thread safety because insertion should __only__ be made
	// on MIHF initialization
	//
	std::map<uint, handler_t>::iterator it;
	it = _callbacks.find(mid);

	if(it != _callbacks.end()) {
		handler_t process_message = it->second;

		bool rsp;

		try {

			rsp = process_message(in, out);

		} catch(mih::bad_tlv) {
			ODTONE_LOG(1, "Discarding malformed message.");
			return false;
		}

		// set ip and port of response message
		out->ip(in->ip());
		out->scope(in->scope());
		out->port(in->port());

		// response message must have the same tid
		out->tid(in->tid());

		return rsp;
	} else {
		ODTONE_LOG(1, "(sac) (warning) message with mid: ", mid,
		    " unknown, discarding.");
	}

	return false;
}
Exemplo n.º 3
0
/**
 * Checks, in the transaction pool, if the incoming message belongs to a pending
 * transaction. If true it runs the transaction, otherwise it creates a new
 * transaction.
 *
 * @param in The input message.
 */
void message_in::operator()(meta_message_ptr& in)
{
	// TODO: FIXME: check page 143 when adding support for fragment payload
	if ((in->ackrsp() && (in->opcode() == mih::operation::request || in->opcode() == mih::operation::indication))
		    ||
	   (!in->ackrsp() && in->opcode() == mih::operation::response)
	        ||
	   (in->ackrsp() && in->opcode() == mih::operation::response && in->has_service_specific_tlv()))
	{		
		// src
		src_transaction_ptr t;
		_tpool.find(in->source(), in->tid(), t);

		if (t) {
			t->in = in;
			t->msg_in_avail = true;

			if (t->start_ack_requestor)
				t->ack_requestor();

			if (t->start_ack_responder)
				t->ack_responder();

			if(t->transaction_status == ONGOING)
				if(!(in->ackrsp() == true && in->opcode() == mih::operation::request))
					t->run();

			if (t->transaction_status != ONGOING && t->ack_requestor_status != ONGOING)
				_tpool.del(t);
		} else {
			new_dst_transaction(in);
		}
	} else {
		dst_transaction_ptr t;
		_tpool.find(in->source(), in->tid(), t);

		if (t) {
			t->in = in;
			t->msg_in_avail = true;

			if (t->start_ack_requestor)
				t->ack_requestor();

			if(t->transaction_status == ONGOING)
				t->run();

			if (t->start_ack_responder && t->transaction_status == ONGOING)
				t->ack_responder();

			if (t->transaction_status != ONGOING && t->ack_requestor_status != ONGOING)
				_tpool.del(t);
		} else {
			new_dst_transaction(in);
		}
        }
}
Exemplo n.º 4
0
/**
 * Checks, in the transaction pool, if the outgoing message belongs to a pending
 * transaction. If true it runs the transaction, otherwise it creates a new
 * transaction.
 *
 * @param out The output message.
 */
void message_out::operator()(meta_message_ptr& out)
{
	out->ackreq(true);	// FIXME: read from config file

	if (out->opcode() == mih::operation::response) {
		dst_transaction_ptr t;
		dst_transaction_set::iterator it;

		_tpool.find(out->destination(), out->tid(), t);

		if (t) {
			t->out = out;
			t->msg_out_avail = true;

			if (t->start_ack_requestor)
				t->ack_requestor();

			if (t->start_ack_responder)
				t->ack_responder();

			if(t->transaction_status == ONGOING)
				t->run();

			if (t->transaction_status != ONGOING && t->ack_requestor_status != ONGOING)
				_tpool.del(t);
		} else {
			new_src_transaction(out);
		}
	} else if ((out->opcode() == mih::operation::indication) || (out->opcode() == mih::operation::request)) {

		src_transaction_ptr t;
		_tpool.find(out->destination(), out->tid(), t);

		if (t) {
			t->out = out;
			t->msg_out_avail = true;

			if (t->start_ack_requestor)
				t->ack_requestor();

			if (t->start_ack_responder)
				t->ack_responder();

			if(t->transaction_status == ONGOING)
				t->run();

			if (t->transaction_status != ONGOING && t->ack_requestor_status != ONGOING)
				_tpool.del(t);
		} else {
			new_src_transaction(out);
		}
	}
}
Exemplo n.º 5
0
/**
 * Link Get Parameters Confirm message handler.
 *
 * @param in input message.
 * @param out output message.
 * @return true if the response is sent immediately or false otherwise.
 */
bool command_service::link_get_parameters_confirm(meta_message_ptr &in,
						   meta_message_ptr &out)
{
	ODTONE_LOG(1, "(mics) received Link_Get_Parameters.confirm from ",
	    in->source().to_string());

	_link_abook.reset(in->source().to_string());

	if(_lpool.set_user_tid(in)) {
		mih::status st;
		boost::optional<mih::link_param_list> lpl;
		boost::optional<mih::link_states_rsp_list> lsrl;
		boost::optional<mih::link_desc_rsp_list> ldrl;

		*in >> mih::confirm(mih::confirm::link_get_parameters)
		       & mih::tlv_status(st)
		       & mih::tlv_link_parameters_status_list(lpl)
		       & mih::tlv_link_states_rsp(lsrl)
		       & mih::tlv_link_descriptor_rsp(ldrl);

		if(st == mih::status_success) {
			mih::link_status_rsp link_status;

			link_status.states_rsp_list = lsrl.get();
			link_status.param_list = lpl.get();
			link_status.desc_rsp_list = ldrl.get();

			_lrpool.add(in->source().to_string(),
			           in->tid(),
			           link_status);
		}

		return false;
	}
Exemplo n.º 6
0
// Check if there's a handler for this message and call it, else
// discard message.
void sac_dispatch::operator()(meta_message_ptr& in)
{
	/** __no__ authentication at this point */

	uint mid = in->mid();

	log(1, "(sac) dispatching message with mid: ", mid);
	//
	// no thread safety because insertion should __only__ be made
	// on MIHF initialization
	//
	std::map<uint, handler_t>::iterator it;
	it = _callbacks.find(mid);

	if(it != _callbacks.end()) {
		handler_t process_message = it->second;
		meta_message_ptr out(new meta_message);

		out->tid(in->tid());
		// send response if it was generated
		if (process_message(in, out))
		 	_transmit(out);
        } else {
		log(1, "(sac) (warning) message with mid: ", mid,
		    " unknown, discarding.");
	}
}
Exemplo n.º 7
0
/**
 * Piggyback local MIHF Capabilities in request message.
 *
 * @param in input message.
 * @param out output message.
 */
void service_management::piggyback_capabilities(meta_message_ptr& in,
												meta_message_ptr& out)
{
	// Get local capabilities
	address_entry mihf_cap = _abook.get(mihfid_t::instance()->to_string());

	*out << mih::request(mih::request::capability_discover)
			& mih::tlv_net_type_addr_list(mihf_cap.capabilities_list_net_type_addr)
			& mih::tlv_event_list(mihf_cap.capabilities_event_list)
			& mih::tlv_command_list(mihf_cap.capabilities_cmd_list)
			& mih::tlv_query_type_list(mihf_cap.capabilities_query_type)
			& mih::tlv_transport_option_list(mihf_cap.capabilities_trans_list)
			& mih::tlv_mbb_ho_supp_list(mihf_cap.capabilities_mbb_ho_supp);

	out->tid(in->tid());
	out->source(in->source());
	out->destination(in->destination());
}
Exemplo n.º 8
0
/**
 * Create a new source transaction for the outgoing message.
 *
 * @param m The output message.
 */
void message_out::new_src_transaction(meta_message_ptr& m)
{
	src_transaction_ptr t(new src_transaction_t(process_message, _netsap));

	_tid++;
	if (_tid == 0)		// don't send a message with a
		_tid = 1;	// transaction id of 0

	_lpool.set_remote_tid(m->destination().to_string(), m->tid(), _tid);
	m->tid(_tid);

	t->out = m;
	t->mid = m->mid();
	t->msg_out_avail = true;

	t->run();

	if (t->transaction_status == ONGOING)
		_tpool.add(t);
}
Exemplo n.º 9
0
// This MIHF is the destination of the Event_Unsubscribe.request.
// Deserialize message, unsubscribe user and send a response
bool event_service::local_event_unsubscribe_request(meta_message_ptr &in,
						    meta_message_ptr &out)
{
	mih::status st;
	mih::link_tuple_id link;
	mih::event_list events;

	*in >> mih::request(mih::request::event_unsubscribe)
		& mih::tlv_link_identifier(link)
		& mih::tlv_event_list(events);

	st = unsubscribe(in->source(), link, events);

	*out << mih::response(mih::response::event_unsubscribe)
		& mih::tlv_status(st)
		& mih::tlv_link_identifier(link)
		& mih::tlv_event_list(events);

	out->tid(in->tid());
	out->destination(in->source());

	return true;
}
Exemplo n.º 10
0
bool sac_process_message(meta_message_ptr& in, meta_message_ptr& out)
{
	// discard messages that this MIHF broadcasted to itself
	if (in->source() == mihfid)
		return false;

	/** __no__ authentication at this point */

	uint mid = in->mid();

	//
	// no thread safety because insertion should __only__ be made
	// on MIHF initialization
	//
	std::map<uint, handler_t>::iterator it;
	it = _callbacks.find(mid);

	if(it != _callbacks.end()) {
		handler_t process_message = it->second;

		bool rsp = process_message(in, out);

		// set ip and port of response message
		out->ip(in->ip());
		out->port(in->port());

		// response message must have the same tid
		out->tid(in->tid());

		return rsp;
	} else {
		log(1, "(sac) (warning) message with mid: ", mid,
		    " unknown, discarding.");
	}

	return false;
}
Exemplo n.º 11
0
/**
 * Check if there is a handler for this message and call it, else
 * discard message.
 *
 * @param in The input message.
 */
void sac_dispatch::operator()(meta_message_ptr& in)
{
	/** __no__ authentication at this point */

	uint mid = in->mid();

	ODTONE_LOG(1, "(sac) dispatching message with mid: ", mid);
	//
	// no thread safety because insertion should __only__ be made
	// on MIHF initialization
	//
	std::map<uint, handler_t>::iterator it;
	it = _callbacks.find(mid);

	if(it != _callbacks.end()) {
		handler_t process_message = it->second;
		meta_message_ptr out(new meta_message);

		out->tid(in->tid());
		// send response if it was generated
		try {

			if (process_message(in, out))
				_transmit(out);

		} catch(mih::bad_tlv) {
			ODTONE_LOG(1, "Discarding malformed message.");
		} catch(unknown_link_sap) {
			ODTONE_LOG(1, "Received message from an unknown Link SAP. Discarding message.");
		} catch(unknown_mih_user) {
			ODTONE_LOG(1, "Received message from an unknown MIH-User. Discarding message.");
		}
	} else {
			ODTONE_LOG(1, "(sac) (warning) message with mid: ", mid,
						  " unknown, discarding.");
	}
}
Exemplo n.º 12
0
	/**
	 * Run Acknowledge Responder State Machine transaction.
	 */
	void ack_responder()
		{
			switch(ack_rsp_state)
			{
			case ACK_RSP_INIT:
				goto _rsp_init_lbl_;
			case ACK_RSP_RETURN_ACK:
				goto _rsp_return_ack_lbl_;
			case ACK_RSP_PIGGYBACKING:
				goto _rsp_piggybacking_lbl_;
			case ACK_RSP_RETURN_DUPLICATE:
				goto _rsp_return_duplicate_lbl_;
			}

		  _rsp_init_lbl_:
			{
				ack->ackreq(false);
				ack->ackrsp(true);
				ack->opcode((mih::operation::type)opcode);
				ack->tid(tid);
				ack->mid(in->mid());
				ack->source(my_mihf_id);
				ack->destination(peer_mihf_id);
				ack->ip(in->ip());
				ack->port(in->port());

				if (msg_out_avail)
					goto _rsp_piggybacking_lbl_;
				else
				{			
					_netsap.send(ack);
					msg_in_avail = false;
					goto _rsp_return_ack_lbl_;
				}
					

				return;
			}

		  _rsp_return_ack_lbl_:
			{
				ack_rsp_state = ACK_RSP_RETURN_ACK;
				if(msg_in_avail)
				{					
					_netsap.send(ack);
					msg_in_avail = false;
				}
				else if (msg_out_avail)
					goto _rsp_piggybacking_lbl_;

				return;
			}

		  _rsp_piggybacking_lbl_:
			{
				ack_rsp_state = ACK_RSP_PIGGYBACKING;

				out->ackrsp(true);
				dup = out;

				if (msg_in_avail)
					goto _rsp_return_duplicate_lbl_;

				return;
			}

		  _rsp_return_duplicate_lbl_:
			{
				ack_rsp_state = ACK_RSP_RETURN_DUPLICATE;
				if (msg_in_avail) {
					_netsap.send(dup);
					msg_in_avail = false;
				}
			}
		}