<commit_before>/*
 * cdptport.cc
 *
 *  Created on: 28.06.2013
 *      Author: andreas
 */

#include <dptlink.h>

using namespace dptmap;

std::map<unsigned int, dptlink*> dptlink::dptlinks;


dptlink&
dptlink::get_dptlink(unsigned int ifindex)
{
	if (dptlink::dptlinks.find(ifindex) == dptlink::dptlinks.end()) {
		throw eDptLinkNotFound();
	}
	return *(dptlink::dptlinks[ifindex]);
}


dptlink::dptlink(
		rofl::crofbase *rofbase,
		rofl::crofdpt *dpt,
		uint32_t of_port_no) :
				rofbase(rofbase),
				dpt(dpt),
				of_port_no(of_port_no),
				tapdev(0),
				ifindex(0)
{
	tapdev = new ctapdev(this, dpt->get_ports()[of_port_no]->get_name(), dpt->get_ports()[of_port_no]->get_hwaddr());

	ifindex = tapdev->get_ifindex();

	dptlink::dptlinks[ifindex] = this;
}



dptlink::~dptlink()
{
	dptlink::dptlinks.erase(ifindex);

	delete_all_neighs();

	delete_all_addrs();

	if (tapdev) delete tapdev;
}



void
dptlink::delete_all_addrs()
{
	for (std::map<uint16_t, dptaddr>::iterator
			it = addrs.begin(); it != addrs.end(); ++it) {
		it->second.flow_mod_delete();
	}
	addrs.clear();
}



void
dptlink::delete_all_neighs()
{
	for (std::map<uint16_t, dptneigh>::iterator
			it = neighs.begin(); it != neighs.end(); ++it) {
		it->second.flow_mod_delete();
	}
	neighs.clear();
}



void
dptlink::enqueue(cnetdev *netdev, rofl::cpacket* pkt)
{
	try {
		if (0 == dpt) {
			throw eDptLinkNoDptAttached();
		}

		ctapdev* tapdev = dynamic_cast<ctapdev*>( netdev );
		if (0 == tapdev) {
			throw eDptLinkTapDevNotFound();
		}

		rofl::cofactions actions(dpt->get_version());
		actions.append_action_output(of_port_no);<commit_msg>suppress outgoing packets (from controller kernel towards data path), if not connected<commit_after>/*
 * cdptport.cc
 *
 *  Created on: 28.06.2013
 *      Author: andreas
 */

#include <dptlink.h>

using namespace dptmap;

std::map<unsigned int, dptlink*> dptlink::dptlinks;


dptlink&
dptlink::get_dptlink(unsigned int ifindex)
{
	if (dptlink::dptlinks.find(ifindex) == dptlink::dptlinks.end()) {
		throw eDptLinkNotFound();
	}
	return *(dptlink::dptlinks[ifindex]);
}


dptlink::dptlink(
		rofl::crofbase *rofbase,
		rofl::crofdpt *dpt,
		uint32_t of_port_no) :
				rofbase(rofbase),
				dpt(dpt),
				of_port_no(of_port_no),
				tapdev(0),
				ifindex(0)
{
	tapdev = new ctapdev(this, dpt->get_ports()[of_port_no]->get_name(), dpt->get_ports()[of_port_no]->get_hwaddr());

	ifindex = tapdev->get_ifindex();

	dptlink::dptlinks[ifindex] = this;
}



dptlink::~dptlink()
{
	dptlink::dptlinks.erase(ifindex);

	delete_all_neighs();

	delete_all_addrs();

	if (tapdev) delete tapdev;
}



void
dptlink::delete_all_addrs()
{
	for (std::map<uint16_t, dptaddr>::iterator
			it = addrs.begin(); it != addrs.end(); ++it) {
		it->second.flow_mod_delete();
	}
	addrs.clear();
}



void
dptlink::delete_all_neighs()
{
	for (std::map<uint16_t, dptneigh>::iterator
			it = neighs.begin(); it != neighs.end(); ++it) {
		it->second.flow_mod_delete();
	}
	neighs.clear();
}



void
dptlink::enqueue(cnetdev *netdev, rofl::cpacket* pkt)
{
	try {
		if ((0 == dpt) || (not dpt->get_channel().is_established())) {
			throw eDptLinkNoDptAttached();
		}

		ctapdev* tapdev = dynamic_cast<ctapdev*>( netdev );
		if (0 == tapdev) {
			throw eDptLinkTapDevNotFound();
		}

		rofl::cofactions actions(dpt->get_version());
		actions.append_action_output(of_port_no);
{'fraction_non_alphanumeric': 0.17300832342449465, 'fraction_numerical': 0.01070154577883472, 'mean_word_length': 4.831889081455806, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3999538', 'n_tokens_mistral': 1542, 'n_tokens_neox': 1410, 'n_words': 218}