async def main(self): connected = OpenflowConnectionStateEvent.createMatcher() ev = await connected pprint(common.dump(ev.connection.openflow_featuresreply, tostr=True)) connection = ev.connection currdef = connection.openflowdef openflow_reply, _ = await of_proto.batch((currdef.nx_set_flow_format.new(format=currdef.NXFF_NXM),), connection, self) for msg in openflow_reply: pprint(common.dump(msg, tostr=True)) openflow_reply = await of_proto.querymultipart( currdef.ofp_stats_request.new( type = currdef.OFPST_DESC ), connection, self) for msg in openflow_reply: pprint(common.dump(msg, tostr=True)) req = currdef.ofp_flow_stats_request.new( table_id = currdef.OFPTT_ALL, out_port = currdef.OFPP_NONE, match = currdef.ofp_match.new(wildcards=currdef.OFPFW_ALL)) openflow_reply = await of_proto.querymultipart(req, connection, self) for msg in openflow_reply: pprint(common.dump(msg, dumpextra = True, typeinfo = common.DUMPTYPE_FLAT, tostr=True)) req = currdef.nx_flow_stats_request.new(table_id = currdef.OFPTT_ALL, out_port = currdef.OFPP_NONE) openflow_reply = await of_proto.querymultipart(req, connection, self) for msg in openflow_reply: pprint(common.dump(msg, dumpextra = True, typeinfo = common.DUMPTYPE_FLAT, tostr=True)) req = currdef.ofp_msg.new() req.header.type = currdef.OFPT_GET_CONFIG_REQUEST openflow_reply = await of_proto.querywithreply(req, connection, self) pprint(common.dump(openflow_reply, tostr=True)) await mgt_conn.shutdown(False)
async def main(self): connectEventMatcher = OpenflowConnectionStateEvent.createMatcher() while True: ev = await connectEventMatcher # here event must be connect event # handle this connection in an subroutine self.connectStateHandler(ev)
def main(self): connected = OpenflowConnectionStateEvent.createMatcher() yield (connected,) pprint(common.dump(self.event.connection.openflow_featuresreply)) connection = self.event.connection currdef = connection.openflowdef for m in of_proto.batch((currdef.nx_set_flow_format.new(format=currdef.NXFF_NXM),), connection, self): yield m for msg in self.openflow_reply: pprint(common.dump(msg)) for m in of_proto.querymultipart(currdef.ofp_stats_request.new( type = currdef.OFPST_DESC), connection, self): yield m for msg in self.openflow_reply: pprint(common.dump(msg)) req = currdef.ofp_flow_stats_request.new( table_id = currdef.OFPTT_ALL, out_port = currdef.OFPP_NONE, match = currdef.ofp_match.new(wildcards=currdef.OFPFW_ALL)) for m in of_proto.querymultipart(req, connection, self): yield m for msg in self.openflow_reply: pprint(common.dump(msg, dumpextra = True, typeinfo = common.DUMPTYPE_FLAT)) req = currdef.nx_flow_stats_request.new(table_id = currdef.OFPTT_ALL, out_port = currdef.OFPP_NONE) for m in of_proto.querymultipart(req, connection, self): yield m for msg in self.openflow_reply: pprint(common.dump(msg, dumpextra = True, typeinfo = common.DUMPTYPE_FLAT)) req = currdef.ofp_msg.new() req.header.type = currdef.OFPT_GET_CONFIG_REQUEST for m in of_proto.querywithreply(req, connection, self): yield m pprint(common.dump(self.openflow_reply)) for m in mgt_conn.shutdown(False): yield m
async def _main(self): # check vlan pool lastend = 0 _check_vlanrange(self.vlanid_pool) flow_init = FlowInitialize.createMatcher(_ismatch= lambda x : self.vhostbind is None or x.vhost in self.vhostbind) conn_down = OpenflowConnectionStateEvent.createMatcher(state = OpenflowConnectionStateEvent.CONNECTION_DOWN, _ismatch= lambda x:self.vhostbind is None or x.createby.vhost in self.vhostbind) while True: ev, m = await M_(flow_init,conn_down) if m is flow_init: conn = ev.connection self.app_routine.subroutine(self._init_conn(conn)) elif m is conn_down: conn = ev.connection self.app_routine.subroutine(self._uninit_conn(conn))
def _manage_conns(self): vb = self.vhostbind self.apiroutine.subroutine(self._manage_existing(), False) try: if vb is not None: conn_up = OpenflowConnectionStateEvent.createMatcher(state = OpenflowConnectionStateEvent.CONNECTION_SETUP, _ismatch = lambda x: x.createby.vhost in vb) conn_down = OpenflowConnectionStateEvent.createMatcher(state = OpenflowConnectionStateEvent.CONNECTION_DOWN, _ismatch = lambda x: x.createby.vhost in vb) else: conn_up = OpenflowConnectionStateEvent.createMatcher(state = OpenflowConnectionStateEvent.CONNECTION_SETUP) conn_down = OpenflowConnectionStateEvent.createMatcher(state = OpenflowConnectionStateEvent.CONNECTION_DOWN) while True: yield (conn_up, conn_down) if self.apiroutine.matcher is conn_up: e = self.apiroutine.event remove = self._add_connection(e.connection) self.scheduler.emergesend(ModuleNotification(self.getServiceName(), 'update', add = [e.connection], remove = remove)) else: e = self.apiroutine.event conns = self.managed_conns.get((e.createby.vhost, e.datapathid)) remove = [] if conns is not None: try: conns.remove(e.connection) except ValueError: pass else: remove.append(e.connection) if not conns: del self.managed_conns[(e.createby.vhost, e.datapathid)] # Also delete from endpoint_conns ep = _get_endpoint(e.connection) econns = self.endpoint_conns.get((e.createby.vhost, ep)) if econns is not None: try: econns.remove(e.connection) except ValueError: pass if not econns: del self.endpoint_conns[(e.createby.vhost, ep)] if remove: self.scheduler.emergesend(ModuleNotification(self.getServiceName(), 'update', add = [], remove = remove)) finally: self.scheduler.emergesend(ModuleNotification(self.getServiceName(), 'unsynchronized'))
def main(self): while True: connectEventMatcher = OpenflowConnectionStateEvent.createMatcher() yield (connectEventMatcher,) # here event must be connect event self.connectStateHandler(self.event)
async def main(self): while True: connectEventMatcher = OpenflowConnectionStateEvent.createMatcher() event = await connectEventMatcher # here event must be connect event self.connectStateHandler(event)
def waitconnection(self, datapathid, auxiliaryid = 0, timeout = 30, vhost = ''): "Wait for a datapath connection" for m in self._wait_for_sync(): yield m c = self._getconnection(datapathid, auxiliaryid, vhost) if c is None: for m in self.apiroutine.waitWithTimeout(timeout, OpenflowConnectionStateEvent.createMatcher(datapathid, auxiliaryid, OpenflowConnectionStateEvent.CONNECTION_SETUP, _ismatch = lambda x: x.createby.vhost == vhost)): yield m if self.apiroutine.timeout: raise ConnectionResetException('Datapath %016x is not connected' % datapathid) self.apiroutine.retvalue = self.apiroutine.event.connection else: self.apiroutine.retvalue = c
def main(self): connected = OpenflowConnectionStateEvent.createMatcher() yield (connected, ) pprint(common.dump(self.event.connection.openflow_featuresreply)) connection = self.event.connection currdef = connection.openflowdef for m in of_proto.querymultipart( currdef.ofp_multipart_request.new(type=currdef.OFPMP_DESC), connection, self): yield m for msg in self.openflow_reply: pprint(common.dump(msg)) for m in of_proto.querymultipart( currdef.ofp_multipart_request.new( type=currdef.OFPMP_PORT_DESC), connection, self): yield m for msg in self.openflow_reply: pprint(common.dump(msg)) req = currdef.ofp_flow_stats_request.new( table_id=currdef.OFPTT_ALL, out_port=currdef.OFPP_ANY, out_group=currdef.OFPG_ANY, match=currdef.ofp_match_oxm.new()) for m in of_proto.querymultipart(req, connection, self): yield m for msg in self.openflow_reply: pprint( common.dump(msg, dumpextra=True, typeinfo=common.DUMPTYPE_FLAT)) req = currdef.ofp_msg.new() req.header.type = currdef.OFPT_GET_CONFIG_REQUEST for m in of_proto.querywithreply(req, connection, self): yield m pprint(common.dump(self.openflow_reply)) req = currdef.ofp_role_request.new(role=currdef.OFPCR_ROLE_NOCHANGE) for m in of_proto.querywithreply(req, connection, self): yield m pprint(common.dump(self.openflow_reply)) req = currdef.ofp_msg.new() req.header.type = currdef.OFPT_GET_ASYNC_REQUEST for m in of_proto.querywithreply(req, connection, self): yield m pprint(common.dump(self.openflow_reply)) for m in mgt_conn.shutdown(False): yield m
def main(self): connected = OpenflowConnectionStateEvent.createMatcher() yield (connected, ) pprint(common.dump(self.event.connection.openflow_featuresreply)) connection = self.event.connection currdef = connection.openflowdef for m in of_proto.batch( (currdef.nx_set_flow_format.new(format=currdef.NXFF_NXM), ), connection, self): yield m for msg in self.openflow_reply: pprint(common.dump(msg)) for m in of_proto.querymultipart( currdef.ofp_stats_request.new(type=currdef.OFPST_DESC), connection, self): yield m for msg in self.openflow_reply: pprint(common.dump(msg)) req = currdef.ofp_flow_stats_request.new( table_id=currdef.OFPTT_ALL, out_port=currdef.OFPP_NONE, match=currdef.ofp_match.new(wildcards=currdef.OFPFW_ALL)) for m in of_proto.querymultipart(req, connection, self): yield m for msg in self.openflow_reply: pprint( common.dump(msg, dumpextra=True, typeinfo=common.DUMPTYPE_FLAT)) req = currdef.nx_flow_stats_request.new(table_id=currdef.OFPTT_ALL, out_port=currdef.OFPP_NONE) for m in of_proto.querymultipart(req, connection, self): yield m for msg in self.openflow_reply: pprint( common.dump(msg, dumpextra=True, typeinfo=common.DUMPTYPE_FLAT)) req = currdef.ofp_msg.new() req.header.type = currdef.OFPT_GET_CONFIG_REQUEST for m in of_proto.querywithreply(req, connection, self): yield m pprint(common.dump(self.openflow_reply)) for m in mgt_conn.shutdown(False): yield m
def waitconnection(self, datapathid, auxiliaryid=0, timeout=30, vhost=''): "Wait for a datapath connection" for m in self._wait_for_sync(): yield m c = self._getconnection(datapathid, auxiliaryid, vhost) if c is None: for m in self.apiroutine.waitWithTimeout( timeout, OpenflowConnectionStateEvent.createMatcher( datapathid, auxiliaryid, OpenflowConnectionStateEvent.CONNECTION_SETUP, _ismatch=lambda x: x.createby.vhost == vhost)): yield m if self.apiroutine.timeout: raise ConnectionResetException( 'Datapath %016x is not connected' % datapathid) self.apiroutine.retvalue = self.apiroutine.event.connection else: self.apiroutine.retvalue = c
def main(self): connected = OpenflowConnectionStateEvent.createMatcher() yield (connected,) pprint(common.dump(self.event.connection.openflow_featuresreply)) connection = self.event.connection currdef = connection.openflowdef for m in of_proto.querymultipart(currdef.ofp_multipart_request.new( type = currdef.OFPMP_DESC), connection, self): yield m for msg in self.openflow_reply: pprint(common.dump(msg)) for m in of_proto.querymultipart(currdef.ofp_multipart_request.new( type = currdef.OFPMP_PORT_DESC), connection, self): yield m for msg in self.openflow_reply: pprint(common.dump(msg)) req = currdef.ofp_flow_stats_request.new( table_id = currdef.OFPTT_ALL, out_port = currdef.OFPP_ANY, out_group = currdef.OFPG_ANY, match = currdef.ofp_match_oxm.new()) for m in of_proto.querymultipart(req, connection, self): yield m for msg in self.openflow_reply: pprint(common.dump(msg, dumpextra = True, typeinfo = common.DUMPTYPE_FLAT)) req = currdef.ofp_msg.new() req.header.type = currdef.OFPT_GET_CONFIG_REQUEST for m in of_proto.querywithreply(req, connection, self): yield m pprint(common.dump(self.openflow_reply)) req = currdef.ofp_role_request.new(role = currdef.OFPCR_ROLE_NOCHANGE) for m in of_proto.querywithreply(req, connection, self): yield m pprint(common.dump(self.openflow_reply)) req = currdef.ofp_msg.new() req.header.type = currdef.OFPT_GET_ASYNC_REQUEST for m in of_proto.querywithreply(req, connection, self): yield m pprint(common.dump(self.openflow_reply)) for m in mgt_conn.shutdown(False): yield m
async def main(self): connected = OpenflowConnectionStateEvent.createMatcher() ev = await connected pprint(common.dump(ev.connection.openflow_featuresreply, tostr=True)) connection = ev.connection currdef = connection.openflowdef openflow_reply = await of_proto.querymultipart( currdef.ofp_multipart_request.new(type=currdef.OFPMP_DESC), connection, self) for msg in openflow_reply: pprint(common.dump(msg, tostr=True)) openflow_reply = await of_proto.querymultipart( currdef.ofp_multipart_request.new(type=currdef.OFPMP_PORT_DESC), connection, self) for msg in openflow_reply: pprint(common.dump(msg, tostr=True)) req = currdef.ofp_flow_stats_request.new( table_id=currdef.OFPTT_ALL, out_port=currdef.OFPP_ANY, out_group=currdef.OFPG_ANY, match=currdef.ofp_match_oxm.new()) openflow_reply = await of_proto.querymultipart(req, connection, self) for msg in openflow_reply: pprint( common.dump(msg, dumpextra=True, typeinfo=common.DUMPTYPE_FLAT, tostr=True)) req = currdef.ofp_msg.new() req.header.type = currdef.OFPT_GET_CONFIG_REQUEST openflow_reply = await of_proto.querywithreply(req, connection, self) pprint(common.dump(openflow_reply, tostr=True)) req = currdef.ofp_role_request.new(role=currdef.OFPCR_ROLE_NOCHANGE) openflow_reply = await of_proto.querywithreply(req, connection, self) pprint(common.dump(openflow_reply, tostr=True)) req = currdef.ofp_msg.new() req.header.type = currdef.OFPT_GET_ASYNC_REQUEST openflow_reply = await of_proto.querywithreply(req, connection, self) pprint(common.dump(openflow_reply, tostr=True)) await mgt_conn.shutdown(False)
async def waitconnection(self, datapathid, auxiliaryid=0, timeout=30, vhost=''): "Wait for a datapath connection" await self._wait_for_sync() c = self._getconnection(datapathid, auxiliaryid, vhost) if c is None: timeout_, ev, _ = await self.apiroutine.wait_with_timeout( timeout, OpenflowConnectionStateEvent.createMatcher( datapathid, auxiliaryid, OpenflowConnectionStateEvent.CONNECTION_SETUP, _ismatch=lambda x: x.createby.vhost == vhost)) if timeout_: raise ConnectionResetException( 'Datapath %016x is not connected' % datapathid) return ev.connection else: return c
def _manage_conns(self): vb = self.vhostbind self.apiroutine.subroutine(self._manage_existing(), False) try: if vb is not None: conn_up = OpenflowConnectionStateEvent.createMatcher( state=OpenflowConnectionStateEvent.CONNECTION_SETUP, _ismatch=lambda x: x.createby.vhost in vb) conn_down = OpenflowConnectionStateEvent.createMatcher( state=OpenflowConnectionStateEvent.CONNECTION_DOWN, _ismatch=lambda x: x.createby.vhost in vb) else: conn_up = OpenflowConnectionStateEvent.createMatcher( state=OpenflowConnectionStateEvent.CONNECTION_SETUP) conn_down = OpenflowConnectionStateEvent.createMatcher( state=OpenflowConnectionStateEvent.CONNECTION_DOWN) while True: yield (conn_up, conn_down) if self.apiroutine.matcher is conn_up: e = self.apiroutine.event remove = self._add_connection(e.connection) self.scheduler.emergesend( ModuleNotification(self.getServiceName(), 'update', add=[e.connection], remove=remove)) else: e = self.apiroutine.event conns = self.managed_conns.get( (e.createby.vhost, e.datapathid)) remove = [] if conns is not None: try: conns.remove(e.connection) except ValueError: pass else: remove.append(e.connection) if not conns: del self.managed_conns[(e.createby.vhost, e.datapathid)] # Also delete from endpoint_conns ep = _get_endpoint(e.connection) econns = self.endpoint_conns.get( (e.createby.vhost, ep)) if econns is not None: try: econns.remove(e.connection) except ValueError: pass if not econns: del self.endpoint_conns[(e.createby.vhost, ep)] if remove: self.scheduler.emergesend( ModuleNotification(self.getServiceName(), 'update', add=[], remove=remove)) finally: self.scheduler.emergesend( ModuleNotification(self.getServiceName(), 'unsynchronized'))