15 #include "rofl/common/croflexception.h"
16 #include "rofl/common/ciosrv.h"
17 #include "rofl/common/crofconn.h"
18 #include "rofl/common/openflow/messages/cofmsg.h"
19 #include "rofl/common/openflow/cofhelloelemversionbitmap.h"
20 #include "rofl/common/crandom.h"
21 #include "rofl/common/ctimerid.h"
22 #include "rofl/common/cauxid.h"
41 static std::set<crofchan_env*> rofchan_envs;
49 { crofchan_env::rofchan_envs.insert(
this); };
56 { crofchan_env::rofchan_envs.erase(
this); };
158 enum crofchan_event_t {
160 EVENT_CONN_ESTABLISHED = 1,
161 EVENT_CONN_TERMINATED = 2,
162 EVENT_CONN_REFUSED = 3,
163 EVENT_CONN_FAILED = 4,
166 enum crofchan_timer_t {
168 TIMER_RUN_ENGINE = 1,
171 enum crofchan_flag_t {
172 FLAG_ENGINE_IS_RUNNING = 0,
182 ofp_version(rofl::openflow::OFP_VERSION_UNKNOWN)
192 versionbitmap(versionbitmap),
193 ofp_version(rofl::openflow::OFP_VERSION_UNKNOWN)
210 is_established()
const;
217 {
return ofp_version; };
223 get_versionbitmap()
const
224 {
return versionbitmap; };
252 get_conn_index()
const;
260 enum rofl::csocket::socket_type_t socket_type,
282 const cauxid& aux_id)
const;
296 const cauxid& aux_id)
const;
304 handle_connect_refused(
crofconn& conn) {
305 rofl::logging::debug2 <<
"[rofl-common][crofchan] "
306 <<
"connection refused, auxid: " << conn.
get_aux_id().str() << std::endl;
307 rofl::RwLock rwlock(conns_refused_rwlock, rofl::RwLock::RWLOCK_WRITE);
309 push_on_eventqueue(EVENT_CONN_REFUSED);
311 for (std::map<rofl::cauxid, crofconn*>::iterator
312 it = conns.begin(); it != conns.end(); ++it) {
316 if (it->second->is_established()) {
318 conns_terminated.push_back(it->first);
321 push_on_eventqueue(EVENT_CONN_TERMINATED);
329 handle_connect_failed(
crofconn& conn) {
330 rofl::logging::debug2 <<
"[rofl-common][crofchan] "
331 <<
"connection failed, auxid: " << conn.
get_aux_id().str() << std::endl;
332 rofl::RwLock rwlock(conns_failed_rwlock, rofl::RwLock::RWLOCK_WRITE);
334 push_on_eventqueue(EVENT_CONN_FAILED);
336 for (std::map<rofl::cauxid, crofconn*>::iterator
337 it = conns.begin(); it != conns.end(); ++it) {
341 if (it->second->is_established()) {
343 conns_terminated.push_back(it->first);
346 push_on_eventqueue(EVENT_CONN_TERMINATED);
354 handle_connected(
crofconn& conn, uint8_t ofp_version) {
355 rofl::logging::debug2 <<
"[rofl-common][crofchan] "
356 <<
"connection established, auxid: "
359 this->ofp_version = ofp_version;
361 for (std::map<cauxid, crofconn*>::iterator
362 it = conns.begin(); it != conns.end(); ++it) {
363 if (0 == it->first.get_id())
365 if (it->second->is_actively_established()) {
366 it->second->reconnect(
true);
371 if (this->ofp_version != ofp_version) {
372 rofl::logging::warn <<
"[rofl-common][crofchan] "
373 <<
"auxiliary connection with invalid OFP version "
374 <<
"negotiated, closing connection. " << conn.str() << std::endl;
381 rofl::RwLock rwlock(conns_established_rwlock, rofl::RwLock::RWLOCK_WRITE);
382 conns_established.push_back(conn.
get_aux_id());
383 push_on_eventqueue(EVENT_CONN_ESTABLISHED);
391 rofl::logging::debug2 <<
"[rofl-common][crofchan] "
392 <<
"connection terminated, auxid: " << conn.
get_aux_id().str() << std::endl;
394 this->ofp_version = rofl::openflow::OFP_VERSION_UNKNOWN;
396 rofl::RwLock rwlock(conns_terminated_rwlock, rofl::RwLock::RWLOCK_WRITE);
397 conns_terminated.push_back(conn.
get_aux_id());
398 push_on_eventqueue(EVENT_CONN_TERMINATED);
400 for (std::map<rofl::cauxid, crofconn*>::iterator
401 it = conns.begin(); it != conns.end(); ++it) {
405 if (it->second->is_established()) {
407 conns_terminated.push_back(it->first);
438 get_sync_xid(
crofconn& conn, uint8_t msg_type = 0, uint16_t msg_sub_type = 0) {
439 return env->
get_sync_xid(*
this, msg_type, msg_sub_type);
446 release_sync_xid(
crofconn& conn, uint32_t xid) {
457 int opaque,
void* data = (
void*)0);
464 enum crofchan_event_t event = EVENT_NONE);
470 work_on_eventqueue();
476 event_conn_established();
482 event_conn_terminated();
488 event_conn_refused();
501 if (crofchan_env::rofchan_envs.find(env) == crofchan_env::rofchan_envs.end()) {
510 operator<< (std::ostream& os,
crofchan const& chan) {
511 os <<
indent(0) <<
"<crofchan established:" << chan.is_established()
512 <<
" ofp-version: " << (int)chan.ofp_version <<
" >" << std::endl;
514 os << chan.versionbitmap;
515 for (std::map<cauxid, crofconn*>::const_iterator
516 it = chan.conns.begin(); it != chan.conns.end(); ++it) {
525 std::stringstream ss;
526 ss <<
"OFP version: " << (int)get_version() <<
" ";
529 (not (conns.begin()->second)->is_established())) {
530 ss <<
" state: -disconnected- ";
532 ss <<
" state: -established- ";
535 for (std::map<cauxid, crofconn*>::const_iterator
536 it = conns.begin(); it != conns.end(); ++it) {
537 ss <<
"{" << (int)it->first.get_id() <<
":"
538 << (it->second->is_established() ?
"-established-" :
"-disconnected-") <<
"} ";
548 std::map<cauxid, crofconn*> conns;
555 std::bitset<32> flags;
557 std::deque<enum crofchan_event_t> events;
560 std::list<rofl::cauxid> conns_established;
564 std::list<rofl::cauxid> conns_terminated;
568 std::list<rofl::cauxid> conns_refused;
572 std::list<rofl::cauxid> conns_failed;
cauxid const & get_aux_id() const
Return auxialiary_id.
Definition: crofconn.h:334
virtual void handle_conn_failed(crofchan &chan, const rofl::cauxid &auxid)
Called in the event of a connection failed (except refused)
Definition: crofchan.h:93
virtual void handle_write(crofchan &chan, const cauxid &auxid)=0
Called after a congestion situation has been resolved.
Definition: cofhelloelemversionbitmap.h:22
Environment expected by a rofl::crofchan instance.
Definition: crofchan.h:40
A single OpenFlow control connection.
Definition: crofconn.h:145
Definition: thread_helper.h:25
Environment expected by a rofl::crofconn instance.
Definition: crofconn.h:40
virtual uint32_t get_async_xid(crofchan &chan)=0
Acquires an OpenFlow transaction ID for an asynchronous message.
Definition: thread_helper.h:88
virtual void handle_conn_terminated(crofchan &chan, const rofl::cauxid &auxid)
Called upon a peer initiated termination of a control connection within the control channel...
Definition: crofchan.h:75
crofchan_env()
crofchan_env constructor
Definition: crofchan.h:48
Definition: crofchan.h:27
virtual ~crofchan_env()
crofchan_env destructor
Definition: crofchan.h:55
Definition: crofchan.h:26
Base class for IO services.
Definition: ciosrv.h:491
Definition: crofchan.h:30
Definition: crofchan.h:29
virtual void handle_conn_established(crofchan &chan, const rofl::cauxid &auxid)
Called upon establishment of a control connection within the control channel.
Definition: crofchan.h:66
Definition: crofchan.h:28
virtual uint32_t get_sync_xid(crofchan &chan, uint8_t msg_type=0, uint16_t msg_sub_type=0)=0
Acquires an OpenFlow transaction ID for a synchronous message.
virtual void recv_message(crofchan &chan, const cauxid &aux_id, rofl::openflow::cofmsg *msg)=0
Called upon reception of an OpenFlow message by the peer entity.
An OpenFlow control channel grouping multiple control connections.
Definition: crofchan.h:154
crofconn & add_conn(const cauxid &aux_id, enum rofl::csocket::socket_type_t socket_type, cparams const &socket_params)
Add a new connection while creating a new crofconn instance and do a socket connect.
Definition: crofchan.cc:69
virtual void release_sync_xid(crofchan &chan, uint32_t xid)=0
Releases a synchronous transaction ID after reception of an OpenFlow reply.
virtual void handle_conn_refused(crofchan &chan, const rofl::cauxid &auxid)
Called in the event of a connection refused.
Definition: crofchan.h:84
Definition: croflexception.h:27