Example #1
0
 def __init__(self, scheduler=None, interval=10.0, server=False):
     RoutineContainer.__init__(self, scheduler, True)
     self.connections = {}
     self.identifiers = {}
     self.idg = 0
     self.interval = interval
     self.server = server
Example #2
0
 def __init__(self, scheduler = None, interval = 10.0, server = False):
     RoutineContainer.__init__(self, scheduler, True)
     self.connections = {}
     self.identifiers = {}
     self.idg = 0
     self.interval = interval
     self.server = server
Example #3
0
    def __init__(self,server):
        super(VXLANVtep,self).__init__(server)
        self.app_routine = RoutineContainer(self.scheduler)
        self.app_routine.main = self._main
        self.routines.append(self.app_routine)

        self.conns = {}
        self.vxlan_vlan_map_info = {}

        self.createAPI(publicapi(self.createioflowparts, self.app_routine,
                                 lambda connection,logicalnetwork,**kwargs:
                                        _is_vxlan(logicalnetwork)),
                       api(self.get_vxlan_bind_info,self.app_routine))
Example #4
0
 def __init__(self, server):
     super(RemoteCall, self).__init__(server)
     self.app_routine = RoutineContainer(self.scheduler)
     # there is no need to run this container main, so don't append it
     # self.routines.append(self.app_routine)
     self.wc = WebClient()
     self.app_routine.main = self._main
     self.routines.append(self.app_routine)
     self.createAPI(api(self.call, self.app_routine))
Example #5
0
 def setUp(self):
     self.server = Server()
     self.rc = RoutineContainer(self.server.scheduler)
Example #6
0
 def __init__(self, scheduler=None, daemon=False):
     RoutineContainer.__init__(self, scheduler=scheduler, daemon=daemon)
Example #7
0
 def __init__(self, scheduler=None, daemon=False):
     RoutineContainer.__init__(self, scheduler=scheduler, daemon=daemon)
Example #8
0
 def __init__(self, scheduler=None, daemon=False):
     RoutineContainer.__init__(self, scheduler=scheduler, daemon=daemon)
     self.encoder = getincrementalencoder('utf-8')
Example #9
0
 def __init__(self, scheduler=None, daemon=False):
     RoutineContainer.__init__(self, scheduler=scheduler, daemon=daemon)
     self.encoder = getincrementalencoder('utf-8')
Example #10
0
class VXLANVtep(FlowBase):
    """
    Use hardware_vtep instead of software VXLAN
    """
    # Use these VLANs for vtep configuration. Must not be conflicted with VLAN networks.
    _default_vlanid_pool = ((3000, 4000),)

    # remote_api means call remote api to vtep controller
    _default_remote_api = True

    # interval time to retry failed actions
    _default_retryactioninterval = 60

    def __init__(self,server):
        super(VXLANVtep,self).__init__(server)
        self.app_routine = RoutineContainer(self.scheduler)
        self.app_routine.main = self._main
        self.routines.append(self.app_routine)

        self.conns = {}
        self.vxlan_vlan_map_info = {}

        self.createAPI(publicapi(self.createioflowparts, self.app_routine,
                                 lambda connection,logicalnetwork,**kwargs:
                                        _is_vxlan(logicalnetwork)),
                       api(self.get_vxlan_bind_info,self.app_routine))

    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))

    async def _init_conn(self,conn):
        if conn in self.conns:
            handler = self.conns.pop(conn)
            handler.close()

        handler = VXLANHandler(conn,self)
        handler.start()
        self.conns[conn] = handler

    async def _uninit_conn(self,conn):
        if conn in self.conns:
            handler = self.conns.pop(conn)
            handler.close()

    async def get_vxlan_bind_info(self,systemid=None):
        """get vxlan -> vlan , bind info"""

        ret = []
        for conn in self.conns:
            datapath_id = conn.openflow_datapathid
            vhost = conn.protocol.vhost

            r = await call_api(self.app_routine,"ovsdbmanager","getbridgeinfo",{"datapathid":datapath_id,
                                                                              "vhost":vhost})

            if r:
                _,system_id,_ = r

                if systemid:
                    if systemid == system_id:
                        handler = self.conns[conn]
                        ret.append({system_id: handler.vxlan_vlan_map_info})
                        break
                else:
                    handler = self.conns[conn]
                    ret.append({system_id:handler.vxlan_vlan_map_info})


        return ret

    async def createioflowparts(self,connection,logicalnetwork,physicalport,logicalnetworkid,physicalportid):

        self._logger.debug(" create flow parts connection = %r",connection)
        self._logger.debug(" create flow parts logicalnetworkid = %r", logicalnetworkid)
        self._logger.debug(" create flow parts physicalportid = %r", physicalportid)

        find = False
        vid = None
        if connection in self.conns:

            handler = self.conns[connection]

            try:
                vid = await handler.wait_vxlan_map_info(self.app_routine,logicalnetwork.id)
            except Exception:
                find = False
                self._logger.warning(" get vxlan vlan map info error", exc_info = True)
            else:
                find = True
                if vid is None:
                    self._logger.warning('Not enough vlan ID, io flow parts not created')
                    find = False
        if find:
            return self.createflowparts(connection, vid, physicalportid)
        else:
            return ([],[],[],[],[])

    def createflowparts(self,connection,vid,physicalportid):
        ofdef = connection.openflowdef
        in_flow_match_part = [
            ofdef.create_oxm(ofdef.OXM_OF_VLAN_VID, vid | ofdef.OFPVID_PRESENT)
        ]

        in_flow_action_part = [
            ofdef.ofp_action(type=ofdef.OFPAT_POP_VLAN)
        ]

        out_flow_action_part = [
            ofdef.ofp_action_push(ethertype=ETHERTYPE_8021Q),
            ofdef.ofp_action_set_field(
                field=ofdef.create_oxm(
                    ofdef.OXM_OF_VLAN_VID,
                    vid | ofdef.OFPVID_PRESENT
                )
            ),
            ofdef.ofp_action_output(
                port=physicalportid
            )
        ]

        out_flow_action_part2 = [
            ofdef.ofp_action_push(ethertype=ETHERTYPE_8021Q),
            ofdef.ofp_action_set_field(
                field=ofdef.create_oxm(
                    ofdef.OXM_OF_VLAN_VID,
                    vid | ofdef.OFPVID_PRESENT
                )
            ),
            ofdef.ofp_action_output(
                port=ofdef.OFPP_IN_PORT
            )
        ]

        group_buckets = [
            ofdef.ofp_action_push(ethertype=ETHERTYPE_8021Q),
            ofdef.ofp_action_set_field(
                field=ofdef.create_oxm(
                    ofdef.OXM_OF_VLAN_VID,
                    vid | ofdef.OFPVID_PRESENT
                )
            ),
            ofdef.ofp_action_output(
                port=physicalportid
            )
        ]

        return in_flow_match_part, in_flow_action_part,out_flow_action_part, group_buckets,out_flow_action_part2