コード例 #1
0
    def _getNFFG(self, nffg_name):
        try:
            logging.debug("Trying to get the NFFG with name %s" % nffg_name)
            resp = requests.get(self.nffg_url % nffg_name,
                                headers=self.headers,
                                timeout=int(self.timeout))
        except Exception as e:
            logging.error("Error during the get of NFFG with name %s : %s" %
                          (nffg_name, e))
            raise ConnectionException(e.message)

        if resp.status_code == 401:
            logging.info(
                "Authentication needed during the get of NFFG with name %s " %
                nffg_name)
            raise NotAuthenticatedException("Not authenticated")

        logging.debug(
            "The get of NFFG with name %s completed wit HTTP status %s" %
            (nffg_name, resp.status_code))
        resp.raise_for_status()

        nffg_dict = json.loads(resp.text)
        ValidateNF_FG().validate(nffg_dict)
        nffg = NF_FG()
        nffg.parseDict(nffg_dict)
        return nffg
コード例 #2
0
    def __init__(self):

        self.counter = 1

        self.nffg_id = "1"
        self.nffg_name = "test_nffg_nat"
        self.tenant_id = "2"
        self.nat_mac = "02:01:02:03:04:05"
        self.nat_lan = {"ip": "192.168.10.1", "netmask": "255.255.255.0"}
        self.lan = u'192.168.10.0/24'

        self.random_str = '' + random.choice(string.ascii_uppercase + string.digits) \
                          + random.choice(string.ascii_uppercase + string.digits)\
                          + random.choice(string.ascii_uppercase + string.digits)

        datastore_url = "http://selforch.name29.net:8081"
        datastore_username = "******"
        datastore_password = "******"

        controller_url = "http://selforch.name29.net:8080"
        controller_username = "******"
        controller_password = "******"

        configuration_url = "http://selforch.name29.net:8082"
        configuration_username = "******"
        configuration_password = "******"

        self.ip_pool = IpPool()

        self.ip_pool.add_ip_in_pool('WAN', '192.168.11.100', '255.255.255.0')
        self.ip_pool.add_ip_in_pool('WAN', '192.168.11.101', '255.255.255.0')
        self.ip_pool.add_ip_in_pool('WAN', '192.168.11.102', '255.255.255.0')
        self.ip_pool.add_ip_in_pool('WAN', '192.168.11.103', '255.255.255.0')
        self.ip_pool.add_ip_in_pool('WAN', '192.168.11.104', '255.255.255.0')
        self.ip_pool.add_ip_in_pool('WAN', '192.168.11.105', '255.255.255.0')
        self.ip_pool.add_ip_in_pool('WAN', '192.168.11.106', '255.255.255.0')
        self.ip_pool.add_ip_in_pool('WAN', '192.168.11.107', '255.255.255.0')
        self.ip_pool.add_ip_in_pool('WAN', '192.168.11.108', '255.255.255.0')
        self.ip_pool.add_ip_in_pool('WAN', '192.168.11.109', '255.255.255.0')

        logging.debug("Service Orchestrator Starting(Log)")

        # start the dd client to receive information about domains
        # base_folder = os.path.realpath(os.path.abspath(os.path.split(inspect.getfile(inspect.currentframe()))[0]))
        # dd_client = DDClient(conf.DD_NAME, conf.BROKER_ADDRESS, conf.DD_CUSTOMER, conf.DD_KEYFILE)
        # thread = Thread(target=dd_client.start)
        # thread.start()

        logging.info("Connecting to the datastore")
        self.datastore = DatastoreClient(username=datastore_username,
                                         password=datastore_password,
                                         base_url=datastore_url)

        logging.info("Connecting to the configuration service")
        self.configuration_service = ConfigurationService(username=configuration_username,
                                                          password=configuration_password,
                                                          base_url=configuration_url,
                                                          timeout=10)

        logging.info("Connecting to the infrastructure orchestrator")
        self.orchestrator = InfrastructureOrchestrator(username=controller_username,
                                                       password=controller_password,
                                                       base_url=controller_url,
                                                       timeout=30000)

        logging.info("Removing old NFFG with name '%s' " % self.nffg_name)

        try:
            self.orchestrator.removeNFFG(self.nffg_name)
        except Exception:
            pass

        logging.debug("Getting template from the datastore")

        self.template_nat = self.datastore.getTemplate("nat")
        template_switch = self.datastore.getTemplate("switch")
        # template_orch = self.datastore.getTemplate("serviceorch")
        template_dhcpserver = self.datastore.getTemplate("dhcpserver")
        template_dhcpserver_man = self.datastore.getTemplate("dhcpserverman")

        logging.debug("Building the VNFs")

        nat_vnf =self.buildVNF(self.template_nat,"NAT"+self.random_str, "NAT"+self.random_str)
        dhcpserver_vnf =self.buildVNF(template_dhcpserver,"DHCPLAN", "DHCPLAN")
        dhcpserver_man_vnf =self.buildVNF(template_dhcpserver_man,"DHCPMAN", "DHCPMAN")

        self.switch_man_vnf =self.buildVNF(template_switch,"SWITCH_MAN", "SWITCH_MAN")
        self.switch_lan_vnf =self.buildVNF(template_switch,"SWITCH_LAN", "SWITCH_LAN")
        self.switch_wan_vnf =self.buildVNF(template_switch,"SWITCH_WAN", "SWITCH_WAN")

        # orch_vnf =self.buildVNF(template_orch,"SELFORCH","serviceorch")

        management_endpoint = EndPoint("MANAGEMENT_ENDPOINT", "MANAGEMENT_ENDPOINT", "host-stack",
                                       configuration="static", ipv4="192.168.40.1/24")
        internet_endpoint = EndPoint("INTERNET_ENDPOINT", "INTERNET_ENDPOINT", "host-stack", configuration="static",
                                     ipv4="192.168.11.1/24")

        logging.debug("Creating the NFFG")
        deploy_nffg = NF_FG(self.nffg_id, self.nffg_name)

        logging.debug("Adding VNF to NFFG")

        # deploy_nffg.addVNF(orch_vnf)
        deploy_nffg.addVNF(nat_vnf)
        deploy_nffg.addVNF(dhcpserver_vnf)
        deploy_nffg.addVNF(dhcpserver_man_vnf)
        deploy_nffg.addVNF(self.switch_man_vnf)
        deploy_nffg.addVNF(self.switch_lan_vnf)
        deploy_nffg.addVNF(self.switch_wan_vnf)
        deploy_nffg.addEndPoint(management_endpoint)
        deploy_nffg.addEndPoint(internet_endpoint)

        logging.debug("Creating link between VNF")

        # Connect SWITCH_MAN to DHCP MAN
        self.link_ports(deploy_nffg,
                        "DHCP_SWITCH_MAN",
                        "SWITCH_MAN_DHCP",
                        dhcpserver_man_vnf.getFullnamePortByLabel("inout"),
                        self.switch_man_vnf.getFullnamePortByLabel(self.switch_man_vnf.getFreePort(deploy_nffg, "port")))

        # Connect SWITCH_LAN to DHCP
        self.link_ports(deploy_nffg,
                        "DHCP_SWITCH_LAN",
                        "SWITCH_LAN_DHCP",
                        dhcpserver_vnf.getFullnamePortByLabel("inout"),
                        self.switch_lan_vnf.getFullnamePortByLabel(
                           self.switch_lan_vnf.getFreePort(deploy_nffg, "port")))

        # Connect Switch_WAN to NAT
        self.link_ports(deploy_nffg,
                       "NAT_SWITCH_WAN",
                       "SWITCH_WAN_NAT",
                        nat_vnf.getFullnamePortByLabel("WAN"),
                        self.switch_wan_vnf.getFullnamePortByLabel(self.switch_wan_vnf.getFreePort(deploy_nffg, "port")))
        # Connect Switch_WAN to INTERNET ENDPOINT
        self.link_ports(deploy_nffg,
                       "INTERNET_SWITCH_WAN",
                       "SWITCH_WAN_INTERNET",
                       "endpoint:INTERNET_ENDPOINT",
                        self.switch_wan_vnf.getFullnamePortByLabel(self.switch_wan_vnf.getFreePort(deploy_nffg, "port")))
        # Connect Endpoint management to Switch_MAN
        self.link_ports(deploy_nffg,
                       "SWITCH_MAN_ENDPOINT",
                       "ENDPOINT_SWITCH_MAN",
                        self.switch_man_vnf.getFullnamePortByLabel(self.switch_man_vnf.getFreePort(deploy_nffg, "port")),
                       "endpoint:MANAGEMENT_ENDPOINT")
        # Connect management port of NAT to Switch_MAN
        self.link_ports(deploy_nffg,
                       "SWITCH_MAN_NAT",
                       "NAT_SWITCH_MAN",
                        self.switch_man_vnf.getFullnamePortByLabel(self.switch_man_vnf.getFreePort(deploy_nffg, "port")),
                        nat_vnf.getFullnamePortByLabel("management"))

        # Connect management port of SELFORCH to Switch_MAN
        # linkPorts(deploy_nffg,"SWITCH_MAN_SELFORCH","SELFORCH_SWITCH_MAN",SWITCH_MAN_vnf.getFullnamePortByLabel(SWITCH_MAN_vnf.getFreePort(deploy_nffg,"port")),orch_vnf.getFullnamePortByLabel("inout"))

        logging.debug("Creating LoadBalancer L2")

        self.load_balancer = LoadBalancerL2(nffg=deploy_nffg,
                                            mac=self.nat_mac,
                                            port_in=self.switch_lan_vnf.getFullnamePortByLabel("port2"),
                                            default_port=nat_vnf.getFullnamePortByLabel("User"))

        logging.info("Sending initial NFFG")
        try:
            self.orchestrator.addNFFG(deploy_nffg)
        except Exception as ex:
            logging.error("Error during the add of the NFFG with name %s" % ex)
            exit(1)

        nat_cfg = ConfigurationSDN(self.tenant_id, self.nffg_id, nat_vnf.id)

        logging.debug("Trying to get one ip for the WAN interface from the Pool")
        nat_wan = self.ip_pool.get('WAN')

        if nat_wan is None:
            logging.error("Error during the get of an ip from the pool '%s' : Pool is empty" % nat_wan)
            exit(1)

        logging.info("WAN IP For the NAT '%s' is '%s'" % (nat_vnf.id,nat_wan["ip"]))

        logging.debug("Configuring the nat VNF")

        nat_cfg.setIP(port="User", ip=self.nat_lan['ip'], netmask=self.nat_lan['netmask'], mac_address=self.nat_mac)
        nat_cfg.setIP(port="WAN", ip=nat_wan['ip'], netmask=nat_wan['netmask'], gateway="192.168.11.1")

        logging.info("Trying to put the configuration for the VNF '%s'" % nat_vnf.id)
        try:
            self.configuration_service.waitUntilStarted(self.tenant_id, self.nffg_id, nat_cfg.vnf_id)
            self.configuration_service.setConfiguration(nat_cfg)
        except Exception as ex:
            logging.error("Error during the put of the configuration for '%s' : '%s'" % (nat_vnf.id, ex))
            exit(1)

        logging.debug("Configuring the NatMonitor")

        self.nat_monitor = NatMonitor(self.configuration_service, self.on_nat_fault, self.on_host_new, self.on_host_left)

        logging.debug("Adding the NAT %s in the NatMonitor" % nat_cfg.vnf_id)

        self.nat_monitor.addNat(self.tenant_id, self.nffg_id, nat_cfg.vnf_id)

        logging.info("Waiting for one host")