void ipv4_exec_reply_get_addr(struct finsFrame *ff, uint64_t src_mac, uint64_t dst_mac) {
	PRINT_DEBUG("Entered: ff=%p, src_mac=%llx, dst_mac=%llx", ff, src_mac, dst_mac);

	struct ip4_store *store = store_list_find(ff->ctrlFrame.serial_num);
	if (store) {
		store_list_remove(store);

		metadata *params = store->ff->metaData;

		uint32_t ether_type = IP4_ETH_TYPE;
		metadata_writeToElement(params, "send_dst_mac", &dst_mac, META_TYPE_INT64);
		metadata_writeToElement(params, "send_src_mac", &src_mac, META_TYPE_INT64);
		metadata_writeToElement(params, "send_ether_type", &ether_type, META_TYPE_INT32);

		PRINT_DEBUG("recv frame: dst=0x%12.12llx, src=0x%12.12llx, type=0x%x", dst_mac, src_mac, ether_type);

		//print_finsFrame(fins_frame);
		ipv4_to_switch(store->ff);
		store->ff = NULL;

		store_free(store);

		freeFinsFrame(ff);
	} else {
		PRINT_ERROR("todo error");
		//TODO error sending back FDF as FCF? saved pdu for that
	}
}
Ejemplo n.º 2
0
int jinni_UDP_to_fins(u_char *dataLocal,int len,uint16_t dstport,uint32_t dst_IP_netformat,
		uint16_t hostport,uint32_t host_IP_netformat)
{

struct finsFrame *ff= (struct finsFrame *) malloc(sizeof (struct finsFrame));

metadata *udpout_meta = (metadata *)malloc(sizeof(metadata));

	PRINT_DEBUG();

	metadata_create(udpout_meta);

	if ( udpout_meta == NULL )
	{
		PRINT_DEBUG("metadata creation failed");
		free(ff);
		exit(1);


	}

	/** metadata_writeToElement() set the value of an element if it already exist
	 * or it creates the element and set its value in case it is new
	 */
	PRINT_DEBUG("%d, %d, %d, %d", dstport,dst_IP_netformat,hostport,
		host_IP_netformat);

	uint32_t dstprt= dstport;
	uint32_t hostprt = hostport;

	metadata_writeToElement(udpout_meta,"dstport",&dstport,META_TYPE_INT);
	metadata_writeToElement(udpout_meta,"srcport",&hostport,META_TYPE_INT);
	metadata_writeToElement(udpout_meta,"dstip",&dst_IP_netformat,META_TYPE_INT);
	metadata_writeToElement(udpout_meta,"srcip",&host_IP_netformat,META_TYPE_INT);


	ff->dataOrCtrl = DATA;
	/**TODO get the address automatically by searching the local copy of the
	 * switch table
	 */
	ff->destinationID.id = UDPID;
	ff->destinationID.next = NULL;
	(ff->dataFrame).directionFlag = DOWN;
	(ff->dataFrame).pduLength = len;
	(ff->dataFrame).pdu = dataLocal;
	(ff->dataFrame).metaData = udpout_meta ;

/**TODO insert the frame into jinni_to_switch queue
 * check if insertion succeeded or not then
 * return 1 on success, or -1 on failure
 * */
	PRINT_DEBUG("");
sem_wait(&Jinni_to_Switch_Qsem);
if (write_queue(ff,Jinni_to_Switch_Queue))
{

sem_post(&Jinni_to_Switch_Qsem);
PRINT_DEBUG("");
	return(1);
}
sem_post(&Jinni_to_Switch_Qsem);
PRINT_DEBUG("");

	return(0);



}
void ipv4_exec_reply(struct finsFrame *ff) {
	PRINT_DEBUG("Entered: ff=%p, meta=%p", ff, ff->metaData);

	int ret = 0;

	metadata *params = ff->metaData;
	if (params) {
		switch (ff->ctrlFrame.param_id) {
		case EXEC_ARP_GET_ADDR:
			PRINT_DEBUG("param_id=EXEC_ARP_GET_ADDR (%d)", ff->ctrlFrame.param_id);

			if (ff->ctrlFrame.ret_val) {
				uint64_t src_mac, dst_mac;
				ret += metadata_readFromElement(params, "src_mac", &src_mac) == META_FALSE;
				ret += metadata_readFromElement(params, "dst_mac", &dst_mac) == META_FALSE;

				if (ret) {
					PRINT_ERROR("ret=%d", ret);
					//TODO send nack
				} else {
					//ipv4_exec_reply_get_addr(ff, src_mac, dst_mac);
					struct ip4_store *store = store_list_find(ff->ctrlFrame.serial_num);
					if (store) {
						PRINT_DEBUG("store=%p, ff=%p, serial_num=%u", store, store->ff, store->serial_num);
						store_list_remove(store);

						uint32_t ether_type = IP4_ETH_TYPE;
						metadata_writeToElement(store->ff->metaData, "send_ether_type", &ether_type, META_TYPE_INT32);
						metadata_writeToElement(store->ff->metaData, "send_dst_mac", &dst_mac, META_TYPE_INT64);
						metadata_writeToElement(store->ff->metaData, "send_src_mac", &src_mac, META_TYPE_INT64);

						PRINT_DEBUG("recv frame: dst=0x%12.12llx, src=0x%12.12llx, type=0x%x", dst_mac, src_mac, ether_type);

						//print_finsFrame(fins_frame);
						ipv4_to_switch(store->ff);
						store->ff = NULL;

						store_free(store);

						freeFinsFrame(ff);
					} else {
						PRINT_ERROR("todo error");
					}
				}
			} else {
				//TODO error sending back FDF as FCF? saved pdu for that
				PRINT_ERROR("todo error");
			}
			break;
		default:
			PRINT_ERROR("Error unknown param_id=%d", ff->ctrlFrame.param_id);
			//TODO implement?
			freeFinsFrame(ff);
			break;
		}
	} else {
		//TODO send nack
		PRINT_ERROR("Error fcf.metadata==NULL");
		freeFinsFrame(ff);
	}
}