Exemplo n.º 1
0
 def test_add_vifinfo(self):
     interface_id = "interface_add"
     datapath_id = "datapath_add"
     port_no = 4
     vlan_id = 104
     ret = ndb.add_vifinfo(interface_id, datapath_id, port_no)
     self.assertTrue(ret.interface_id == interface_id)
     self.assertTrue(ret.datapath_id == datapath_id)
     self.assertTrue(ret.port_no == port_no)
     self.assertTrue(ret.vlan_id == 65535)
     ret = ndb.get_vifinfo(interface_id)
     self.assertTrue(ret.interface_id == interface_id)
     self.assertTrue(ret.datapath_id == datapath_id)
     self.assertTrue(ret.port_no == port_no)
     self.assertTrue(ret.vlan_id == 65535)
     ndb.del_vifinfo(interface_id)
     ret = ndb.add_vifinfo(interface_id, datapath_id, port_no, vlan_id)
     self.assertTrue(ret.interface_id == interface_id)
     self.assertTrue(ret.datapath_id == datapath_id)
     self.assertTrue(ret.port_no == port_no)
     self.assertTrue(ret.vlan_id == vlan_id)
     ret = ndb.get_vifinfo(interface_id)
     self.assertTrue(ret.interface_id == interface_id)
     self.assertTrue(ret.datapath_id == datapath_id)
     self.assertTrue(ret.port_no == port_no)
     self.assertTrue(ret.vlan_id == vlan_id)
     ndb.del_vifinfo(interface_id)
Exemplo n.º 2
0
 def test_get_vifinfo(self):
     interface_id = "interface_get"
     datapath_id = "datapath_get"
     port_no = 1
     vlan_id = 101
     ret = ndb.get_vifinfo(interface_id)
     self.assertTrue(ret == None)
     ndb.add_vifinfo(interface_id, datapath_id, port_no, vlan_id)
     ret = ndb.get_vifinfo(interface_id)
     self.assertTrue(ret.interface_id == interface_id)
     self.assertTrue(ret.datapath_id == datapath_id)
     self.assertTrue(ret.port_no == port_no)
     self.assertTrue(ret.vlan_id == vlan_id)
     ndb.del_vifinfo(interface_id)
Exemplo n.º 3
0
    def _attach(self, tenant_id, network_id, port_id, interface_id):
        LOG.debug("_attach(): called")
        ofn_tenant_id = self._get_ofn_tenant_id(tenant_id)
        ofn_network_id = self._get_ofn_network_id(network_id)
        vifinfo = ndb.get_vifinfo(interface_id)

        if self.conf.auto_id_port:
            """id include response."""
            res = self.ofn.ofn_create_port(ofn_tenant_id,
                                           ofn_network_id,
                                           vifinfo.datapath_id,
                                           str(vifinfo.port_no),
                                           str(vifinfo.vlan_id))
            ofn_port_id = res['id']
        else:
            """use uuid for ofn_network."""
            ofn_port_id = port_id
            res = self.ofn.ofn_create_port(ofn_tenant_id,
                                           ofn_network_id,
                                           vifinfo.datapath_id,
                                           str(vifinfo.port_no),
                                           str(vifinfo.vlan_id),
                                           ofn_port_id)
        LOG.debug("_attach(): ofn_create_port() return '%s'" % res)
        LOG.debug("_attach(): ofn_port_id = %s" % ofn_port_id)
        ndb.add_ofn_port(ofn_port_id, port_id)
Exemplo n.º 4
0
 def test_del_vifinfo(self):
     interface_id = "interface_del"
     datapath_id = "datapath_del"
     port_no = 5
     vlan_id = 105
     ndb.add_vifinfo(interface_id, datapath_id, port_no)
     ndb.del_vifinfo(interface_id)
     ret = ndb.get_vifinfo(interface_id)
     self.assertTrue(ret == None)
Exemplo n.º 5
0
 def get_vifinfo(self, interface_id):
     LOG.debug("get_vifinfo() called")
     vifinfo = ndb.get_vifinfo(interface_id)
     if not vifinfo:
         return None
     return {'vifinfo': {
               'interface_id': vifinfo.interface_id,
                'ofs_port': {'datapath_id': vifinfo.datapath_id,
                             'port_no': str(vifinfo.port_no)}}}
Exemplo n.º 6
0
 def _port_attachable(self, port):
     if not port:
         return False
     if not port.interface_id:
         return False
     if not port.state.upper() in "ACTIVE":
         return False
     if not ndb.get_vifinfo(port.interface_id):
         return False
     return True
Exemplo n.º 7
0
 def __init__(self, config_file=None):
     self.conf = NECConfig(config_file)
     self.ofn = OFNetwork(self.conf.OFC_HOST, self.conf.OFC_PORT)
     ndb.initialize(self.conf)
     if self.conf.vif_file:
         vifinfo_list = self.conf.load_vifinfo(self.conf.vif_file)
         for vifinfo in vifinfo_list:
             old_vifinfo = ndb.get_vifinfo(vifinfo['interface_id'])
             if old_vifinfo:
                 LOG.info("Delete old vifinfo %s." % old_vifinfo)
                 ndb.del_vifinfo(vifinfo['interface_id'])
             ndb.add_vifinfo(vifinfo['interface_id'],
                             vifinfo['datapath_id'],
                             vifinfo['port_no'],
                             vifinfo['vlan_id'])