<commit_before>/*
 * ccookies.hpp
 *
 *  Created on: 19.11.2014
 *      Author: andreas
 */

#ifndef CCOOKIES_HPP_
#define CCOOKIES_HPP_

#include <inttypes.h>

#include <rofl/common/crofdpt.h>
#include <rofl/common/cauxid.h>
#include <rofl/common/crandom.h>
#include <rofl/common/openflow/messages/cofmsg_packet_in.h>
#include <rofl/common/openflow/messages/cofmsg_flow_removed.h>

#include "roflibs/netlink/clogging.hpp"

namespace roflibs {
namespace common {
namespace openflow {

class ccookiebox; // forward declaration, see below

class ccookie_owner {
public:

	/**
	 *
	 */
	virtual
	~ccookie_owner();

public:

	/**
	 *
	 */
	uint64_t
	acquire_cookie();

	/**
	 *
	 */
	void
	release_cookie(uint64_t cookie);

protected:

	friend class ccookiebox;

	/**
	 *
	 */
	virtual void
	handle_packet_in(
			rofl::crofdpt& dpt, const rofl::cauxid& auxid, rofl::openflow::cofmsg_packet_in& msg) = 0;

	/**
	 *
	 */
	virtual void
	handle_flow_removed(
			rofl::crofdpt& dpt, const rofl::cauxid& auxid, rofl::openflow::cofmsg_flow_removed& msg) = 0;
};



class ccookie_find_by_owner {
	ccookie_owner* owner;
public:
	ccookie_find_by_owner(ccookie_owner* owner) :
		owner(owner) {};
	bool operator() (const std::pair<uint64_t, ccookie_owner*>& p) {
		return (p.second == owner);
	};
};



class ccookiebox {
private:

	static ccookiebox* 					cookiebox;
	uint64_t 							next_cookie;
	std::map<uint64_t, ccookie_owner*> 	cookiestore;
	ccookiebox() : next_cookie(rofl::crandom(8).uint64()) {};
	~ccookiebox() {};

public:

	/**
	 *
	 */
	static ccookiebox&
	get_instance() {
		if ((ccookiebox*)0 == ccookiebox::cookiebox) {
			ccookiebox::cookiebox = new ccookiebox();
		}
		return *(ccookiebox::cookiebox);
	};

	/**
	 *
	 */
	void
	handle_packet_in(
			rofl::crofdpt& dpt, const rofl::cauxid& auxid, rofl::openflow::cofmsg_packet_in& msg) {
		if (cookiestore.find(msg.get_cookie()) == cookiestore.end()) {
			rofcore::logging::debug << "[ccookiebox][handle_packet_in] cookie:" << (unsigned long long)msg.get_cookie()
					<< " not found, dropping packet" << std::endl;
			return;
		}
		cookiestore[msg.get_cookie()]->handle_packet_in(dpt, auxid, msg);
	};

	/**
	 *
	 */
	void
	handle_flow_removed(
			rofl::crofdpt& dpt, const rofl::cauxid& auxid, rofl::openflow::cofmsg_flow_removed& msg) {
		if (cookiestore.find(msg.get_cookie()) == cookiestore.end()) {
			rofcore::logging::debug << "[ccookiebox][handle_flow_removed] cookie:" << (unsigned long long)msg.get_cookie()
					<< " not found, dropping packet" << std::endl;
			return;
		}
		cookiestore[msg.get_cookie()]->handle_flow_removed(dpt, auxid, msg);
	};

private:

	friend class ccookie_owner;
<commit_msg>ccookiebox => revised debug output<commit_after>/*
 * ccookies.hpp
 *
 *  Created on: 19.11.2014
 *      Author: andreas
 */

#ifndef CCOOKIES_HPP_
#define CCOOKIES_HPP_

#include <inttypes.h>

#include <rofl/common/crofdpt.h>
#include <rofl/common/cauxid.h>
#include <rofl/common/crandom.h>
#include <rofl/common/openflow/messages/cofmsg_packet_in.h>
#include <rofl/common/openflow/messages/cofmsg_flow_removed.h>

#include "roflibs/netlink/clogging.hpp"

namespace roflibs {
namespace common {
namespace openflow {

class ccookiebox; // forward declaration, see below

class ccookie_owner {
public:

	/**
	 *
	 */
	virtual
	~ccookie_owner();

public:

	/**
	 *
	 */
	uint64_t
	acquire_cookie();

	/**
	 *
	 */
	void
	release_cookie(uint64_t cookie);

protected:

	friend class ccookiebox;

	/**
	 *
	 */
	virtual void
	handle_packet_in(
			rofl::crofdpt& dpt, const rofl::cauxid& auxid, rofl::openflow::cofmsg_packet_in& msg) = 0;

	/**
	 *
	 */
	virtual void
	handle_flow_removed(
			rofl::crofdpt& dpt, const rofl::cauxid& auxid, rofl::openflow::cofmsg_flow_removed& msg) = 0;
};



class ccookie_find_by_owner {
	ccookie_owner* owner;
public:
	ccookie_find_by_owner(ccookie_owner* owner) :
		owner(owner) {};
	bool operator() (const std::pair<uint64_t, ccookie_owner*>& p) {
		return (p.second == owner);
	};
};



class ccookiebox {
private:

	static ccookiebox* 					cookiebox;
	uint64_t 							next_cookie;
	std::map<uint64_t, ccookie_owner*> 	cookiestore;
	ccookiebox() : next_cookie(rofl::crandom(8).uint64()) {};
	~ccookiebox() {};

public:

	/**
	 *
	 */
	static ccookiebox&
	get_instance() {
		if ((ccookiebox*)0 == ccookiebox::cookiebox) {
			ccookiebox::cookiebox = new ccookiebox();
		}
		return *(ccookiebox::cookiebox);
	};

	/**
	 *
	 */
	void
	handle_packet_in(
			rofl::crofdpt& dpt, const rofl::cauxid& auxid, rofl::openflow::cofmsg_packet_in& msg) {
		if (cookiestore.find(msg.get_cookie()) == cookiestore.end()) {
			rofcore::logging::debug << "[ccookiebox][handle_packet_in] cookie:"
					<< std::hex << (unsigned long long)msg.get_cookie() << std::dec
					<< " not found, dropping packet" << std::endl;
			return;
		}
		cookiestore[msg.get_cookie()]->handle_packet_in(dpt, auxid, msg);
	};

	/**
	 *
	 */
	void
	handle_flow_removed(
			rofl::crofdpt& dpt, const rofl::cauxid& auxid, rofl::openflow::cofmsg_flow_removed& msg) {
		if (cookiestore.find(msg.get_cookie()) == cookiestore.end()) {
			rofcore::logging::debug << "[ccookiebox][handle_flow_removed] cookie:"
					<< std::hex << (unsigned long long)msg.get_cookie() << std::dec
					<< " not found, dropping packet" << std::endl;
			return;
		}
		cookiestore[msg.get_cookie()]->handle_flow_removed(dpt, auxid, msg);
	};

private:

	friend class ccookie_owner;

{'fraction_non_alphanumeric': 0.158624514697726, 'fraction_numerical': 0.00887409872434831, 'mean_word_length': 4.3938185443669, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 24, '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': '4992486', 'n_tokens_mistral': 2276, 'n_tokens_neox': 2092, 'n_words': 357}