<commit_before>/*
 * cethcore.cpp
 *
 *  Created on: 03.08.2014
 *      Author: andreas
 */

#include "cethcore.hpp"

using namespace roflibs::ethernet;

/*static*/std::map<rofl::cdpid, cethcore*> cethcore::ethcores;
/*static*/std::set<uint64_t> cethcore::dpids;


cethcore::cethcore(const rofl::cdpid& dpid,
		uint8_t table_id_eth_in, uint8_t table_id_eth_src,
		uint8_t table_id_eth_local, uint8_t table_id_eth_dst,
		uint16_t default_pvid) :
	state(STATE_IDLE), dpid(dpid), default_pvid(default_pvid),
	table_id_eth_in(table_id_eth_in),
	table_id_eth_src(table_id_eth_src),
	table_id_eth_local(table_id_eth_local),
	table_id_eth_dst(table_id_eth_dst) {
	if (cethcore::ethcores.find(dpid) != cethcore::ethcores.end()) {
		throw eVlanExists("cethcore::cethcore() dpid already exists");
	}
	cethcore::ethcores[dpid] = this;

	rofl::crofdpt& dpt = rofl::crofdpt::get_dpt(dpid);

	std::string dbname("file");
	for (std::map<uint32_t, rofl::openflow::cofport*>::const_iterator
			it = dpt.get_ports().get_ports().begin(); it != dpt.get_ports().get_ports().end(); ++it) {
		if (not cportdb::get_portdb(dbname).has_port_entry(dpid, it->first)) {
			continue;
		}
		const rofl::openflow::cofport& ofport = *(it->second);
		const cportentry& port = cportdb::get_portdb(dbname).get_port_entry(dpid, it->first);

		// create or maintain existing vlan for port's default vid
		set_vlan(port.get_port_vid()).add_port(port.get_portno(), /*tagged=*/false);

		// add all tagged memberships of this port to the appropriate vlan
		for (std::set<uint16_t>::const_iterator
				jt = port.get_tagged_vids().begin(); jt != port.get_tagged_vids().end(); ++jt) {
			set_vlan(*jt).add_port(port.get_portno(), ofport.get_hwaddr(), /*tagged=*/true);
		}
	}
}


cethcore::~cethcore() {
	if (STATE_ATTACHED == state) {
		// TODO
	}
	cethcore::ethcores.erase(dpid);
}


void
cethcore::handle_dpt_open(rofl::crofdpt& dpt)
{
	try {
		state = STATE_ATTACHED;

		for (std::map<uint16_t, cvlan>::iterator
				it = vlans.begin(); it != vlans.end(); ++it) {
			if (it->second.get_group_id() != 0) {
				dpt.release_group_id(it->second.get_group_id());
			}
			it->second.handle_dpt_open(dpt);
		}
<commit_msg>cethcore => constructor => when reading a port from portdb, use hwaddr reported by datapath only, when no hwaddr is defined in portdb<commit_after>/*
 * cethcore.cpp
 *
 *  Created on: 03.08.2014
 *      Author: andreas
 */

#include "cethcore.hpp"

using namespace roflibs::ethernet;

/*static*/std::map<rofl::cdpid, cethcore*> cethcore::ethcores;
/*static*/std::set<uint64_t> cethcore::dpids;


cethcore::cethcore(const rofl::cdpid& dpid,
		uint8_t table_id_eth_in, uint8_t table_id_eth_src,
		uint8_t table_id_eth_local, uint8_t table_id_eth_dst,
		uint16_t default_pvid) :
	state(STATE_IDLE), dpid(dpid), default_pvid(default_pvid),
	table_id_eth_in(table_id_eth_in),
	table_id_eth_src(table_id_eth_src),
	table_id_eth_local(table_id_eth_local),
	table_id_eth_dst(table_id_eth_dst) {
	if (cethcore::ethcores.find(dpid) != cethcore::ethcores.end()) {
		throw eVlanExists("cethcore::cethcore() dpid already exists");
	}
	cethcore::ethcores[dpid] = this;

	rofl::crofdpt& dpt = rofl::crofdpt::get_dpt(dpid);

	std::string dbname("file");
	for (std::map<uint32_t, rofl::openflow::cofport*>::const_iterator
			it = dpt.get_ports().get_ports().begin(); it != dpt.get_ports().get_ports().end(); ++it) {
		if (not cportdb::get_portdb(dbname).has_port_entry(dpid, it->first)) {
			continue;
		}
		const rofl::openflow::cofport& ofport = *(it->second);
		const cportentry& port = cportdb::get_portdb(dbname).get_port_entry(dpid, it->first);

		// create or maintain existing vlan for port's default vid
		set_vlan(port.get_port_vid()).add_port(port.get_portno(), /*tagged=*/false);

		// if a hwaddr is specified for this port in portdb, use that one,
		// if not, use the hwaddr reported by the data path itself
		rofl::caddress_ll hwaddr = ofport.get_hwaddr();
		if (not port.get_hwaddr().is_null()) {
			hwaddr = port.get_hwaddr();
		}

		// add all tagged memberships of this port to the appropriate vlan
		for (std::set<uint16_t>::const_iterator
				jt = port.get_tagged_vids().begin(); jt != port.get_tagged_vids().end(); ++jt) {
			set_vlan(*jt).add_port(port.get_portno(), hwaddr, /*tagged=*/true);
		}
	}
}


cethcore::~cethcore() {
	if (STATE_ATTACHED == state) {
		// TODO
	}
	cethcore::ethcores.erase(dpid);
}


void
cethcore::handle_dpt_open(rofl::crofdpt& dpt)
{
	try {
		state = STATE_ATTACHED;

		for (std::map<uint16_t, cvlan>::iterator
				it = vlans.begin(); it != vlans.end(); ++it) {
			if (it->second.get_group_id() != 0) {
				dpt.release_group_id(it->second.get_group_id());
			}
			it->second.handle_dpt_open(dpt);
		}

{'fraction_non_alphanumeric': 0.16298811544991512, 'fraction_numerical': 0.009762308998302207, 'mean_word_length': 5.31769436997319, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 27, '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': '647340', 'n_tokens_mistral': 2044, 'n_tokens_neox': 1899, 'n_words': 314}