Пример #1
0
    def __init__(self, dd_controller, curr_whitelist):
        self.EVENT_ADD = Constants.EVENT_ADD
        self.EVENT_UPDATE = Constants.EVENT_UPDATE
        self.EVENT_DELETE = Constants.EVENT_DELETE

        ######################### YANG CONSTANTS #########################
        self.SILENT = Constants.ADVERTISE_SILENT
        self.ON_CHANGE = Constants.ADVERTISE_ON_CHANGE
        self.PERIODIC = Constants.ADVERTISE_PERIODIC

        self.url_whitelist = "config-firewall:firewall/whitelist"
        self.url_name = "/url"

        self.elements = {}
        self.elements['url'] = Element(advertise=self.ON_CHANGE)
        ##################################################################

        self.periods = []
        for key, element in self.elements.items():
            if element.advertise == self.PERIODIC:
                element.period = element.period / 1000
                if element.period not in self.periods:
                    self.periods.append(element.period)

        self.on_change_interval = ConfigurationInstance().get_on_change_interval()
        logging.debug("on_change_interval: " + str(self.on_change_interval))

        self.whitelist_old = curr_whitelist
        print("whitelist_old: " + str(len(self.whitelist_old)))
        self.whitelist_new = []
        self.whitelist_updated = []
        self.whitelist_removed = []

        self.ddController = dd_controller
        self.whitelistController = WhitelistController()
Пример #2
0
    def _read_metadata_file(self, metadata_path):
        """
        It reads the volume attached to the VNF (datadisk) and looks for the information the VNF needs
        It excpects to find a metadata file describing the VNF's name, ID and tenant ID
        :param ds_metadata:
        :return:
        """
        try:
            with open(metadata_path) as metadata_file:

                json_data = metadata_file.read()
                metadata = json.loads(json_data)

                assert 'tenant-id' in metadata, "tenant-id key not found in metadata file"
                assert 'graph-id' in metadata, "graph-id key not found in metadata file"
                assert 'vnf-id' in metadata, "vnf-id key not found in metadata file"
                assert 'broker-url' in metadata, "broker-url key not found in metadata file"

                self.tenant_id = metadata['tenant-id']
                self.graph_id = metadata['graph-id']
                self.vnf_id = metadata['vnf-id']
                triple = self.tenant_id + '.' + self.graph_id + '.' + self.vnf_id
                ConfigurationInstance().save_triple(triple)
                self.broker_url = metadata['broker-url']

        except Exception as e:
            logging.debug("Error during metadata reading.\n" + str(e))
            sys.exit(1)
Пример #3
0
    def __init__(self, dd_controller, curr_nat_sessions):
        self.EVENT_ADD = Constants.EVENT_ADD
        self.EVENT_UPDATE = Constants.EVENT_UPDATE
        self.EVENT_DELETE = Constants.EVENT_DELETE

        ######################### YANG CONSTANTS #########################
        self.SILENT = Constants.ADVERTISE_SILENT
        self.ON_CHANGE = Constants.ADVERTISE_ON_CHANGE
        self.PERIODIC = Constants.ADVERTISE_PERIODIC

        self.url_natSession = "config-nat:nat/nat-table/nat-session"

        self.elements = {}
        self.elements['natSession'] = Element(advertise=self.ON_CHANGE)
        ##################################################################

        self.periods = []
        for key, element in self.elements.items():
            if element.advertise == self.PERIODIC:
                element.period = element.period / 1000
                if element.period not in self.periods:
                    self.periods.append(element.period)

        self.on_change_interval = ConfigurationInstance(
        ).get_on_change_interval()
        logging.debug("on_change_interval: " + str(self.on_change_interval))

        self.nat_sessions_old = curr_nat_sessions
        print("nat_sessions_old: " + str(len(self.nat_sessions_old)))
        self.nat_sessions_new = []
        self.nat_sessions_removed = []

        self.ddController = dd_controller
        self.natTableController = NatTableController()
        self.natTableParser = NatTableParser()
Пример #4
0
    def get_interfaces(self):
        iface_management = ConfigurationInstance().get_iface_management()
        interfaces = []
        net_ifaces = netifaces.interfaces()
        for net_iface in net_ifaces:

            if net_iface.__eq__("lo") or net_iface.__eq__(
                    "gre0") or net_iface.__eq__("gretap0"):
                continue

            name = net_iface

            id = dbManager().read_interface_id(name)
            if id == None:
                id = "not_defined"

            type = "not_defined"

            if name == iface_management:
                management = True
            else:
                management = False

            configuration_type = "not_defined"
            ipv4_address = None
            netmask = None
            mac_address = None
            default_gw = None

            # get ipv4_address and netmask
            if 2 in netifaces.ifaddresses(net_iface):
                interface_af_inet_info = netifaces.ifaddresses(net_iface)[2]
                ipv4_address = interface_af_inet_info[0]['addr']
                netmask = interface_af_inet_info[0]['netmask']

            # get mac_addres
            mac_address = netifaces.ifaddresses(net_iface)[
                netifaces.AF_LINK][0]['addr']

            # get default_gw
            gws = netifaces.gateways()
            if gws['default'] != {} and gws['default'][
                    netifaces.AF_INET][1] == net_iface:
                default_gw = gws['default'][netifaces.AF_INET][0]

            ipv4_configuration = Ipv4Configuration(
                configuration_type=configuration_type,
                address=ipv4_address,
                netmask=netmask,
                mac_address=mac_address,
                default_gw=default_gw)

            interface = Interface(id=id,
                                  name=name,
                                  type=type,
                                  management=management,
                                  ipv4_configuration=ipv4_configuration)
            interfaces.append(interface)

        return interfaces
Пример #5
0
    def __init__(self, dd_controller, curr_dhcpServer_configuration):

        self.EVENT_ADD = Constants.EVENT_ADD
        self.EVENT_UPDATE = Constants.EVENT_UPDATE
        self.EVENT_DELETE = Constants.EVENT_DELETE

        ######################### YANG CONSTANTS #########################
        self.SILENT = Constants.ADVERTISE_SILENT
        self.ON_CHANGE = Constants.ADVERTISE_ON_CHANGE
        self.PERIODIC = Constants.ADVERTISE_PERIODIC

        self.url_dhcpServerConfiguration = "config-dhcp-server:server/"
        self.url_defaultLeaseTime = self.url_dhcpServerConfiguration + "/defaultLeaseTime"
        self.url_maxLeaseTime = self.url_dhcpServerConfiguration + "/maxLeaseTime"
        self.url_subnet = self.url_dhcpServerConfiguration + "/subnet"
        self.url_subnetMask = self.url_dhcpServerConfiguration + "/subnetMask"
        self.url_router = self.url_dhcpServerConfiguration + "/router"
        self.url_dns_primaryServer = self.url_dhcpServerConfiguration + "/dnsPrimaryServer"
        self.url_dns_secondaryServer = self.url_dhcpServerConfiguration + "/dnsSecondaryServer"
        self.url_dns_domainName = self.url_dhcpServerConfiguration + "/dnsDomainName"
        self.url_sections = self.url_dhcpServerConfiguration + "/sections"
        self.url_section_startIP = "/sectionStartIp"
        self.url_section_endIP = "/sectionEndIp"

        self.elements = {}
        self.elements['server'] = Element(advertise=self.ON_CHANGE)
        self.elements['defaultLeaseTime'] = Element(advertise=self.SILENT)
        self.elements['maxLeaseTime'] = Element(advertise=self.SILENT)
        self.elements['subnet'] = Element(advertise=self.SILENT)
        self.elements['subnetMask'] = Element(advertise=self.SILENT)
        self.elements['router'] = Element(advertise=self.SILENT)
        self.elements['dnsPrimaryServer'] = Element(advertise=self.SILENT)
        self.elements['dnsSecondaryServer'] = Element(advertise=self.SILENT)
        self.elements['dnsDomainName'] = Element(advertise=self.SILENT)
        self.elements['sections'] = Element(advertise=self.SILENT)
        self.elements['section'] = Element(advertise=self.SILENT)
        self.elements['sectionStartIp'] = Element(advertise=self.SILENT)
        self.elements['sectionEndIp'] = Element(advertise=self.SILENT)
        ##################################################################

        self.periods = []
        for key, element in self.elements.items():
            if element.advertise == self.PERIODIC:
                element.period = element.period / 1000
                if element.period not in self.periods:
                    self.periods.append(element.period)

        self.on_change_interval = ConfigurationInstance().get_on_change_interval()
        logging.debug("on_change_interval: " + str(self.on_change_interval))

        self.dhcpServerConfig_old = curr_dhcpServer_configuration
        self.dhcpServerConfig_new = None

        self.ddController = dd_controller
        self.dhcpServerController = DhcpServerController()
        self.dhcpServerParser = DhcpServerParser()
Пример #6
0
    def __init__(self, dd_controller, curr_dhcp_clients):

        self.EVENT_ADD = Constants.EVENT_ADD
        self.EVENT_UPDATE = Constants.EVENT_UPDATE
        self.EVENT_DELETE = Constants.EVENT_DELETE

        ######################### YANG CONSTANTS #########################
        self.SILENT = Constants.ADVERTISE_SILENT
        self.ON_CHANGE = Constants.ADVERTISE_ON_CHANGE
        self.PERIODIC = Constants.ADVERTISE_PERIODIC

        self.url_clients = "config-dhcp-server:server/clients"

        self.elements = {}
        self.elements['client'] = Element(advertise=self.ON_CHANGE)
        ##################################################################

        self.periods = []
        for key, element in self.elements.items():
            if element.advertise == self.PERIODIC:
                element.period = element.period / 1000
                if element.period not in self.periods:
                    self.periods.append(element.period)

        self.on_change_interval = ConfigurationInstance(
        ).get_on_change_interval()
        logging.debug("on_change_interval: " + str(self.on_change_interval))

        self.dhcp_clients_old = curr_dhcp_clients
        logging.debug("dhcp_clients_old: " + str(len(self.dhcp_clients_old)))
        self.dhcp_clients_new = []
        self.dhcp_clients_updated = []
        self.dhcp_clients_removed = []

        self.ddController = dd_controller
        self.dhcpClientController = DhcpClientController()
        self.dhcpClientParser = DhcpClientParser()
Пример #7
0
    def __init__(self, dd_controller, curr_interfaces):

        self.EVENT_ADD = Constants.EVENT_ADD
        self.EVENT_UPDATE = Constants.EVENT_UPDATE
        self.EVENT_DELETE = Constants.EVENT_DELETE

        ######################### YANG CONSTANTS #########################
        self.SILENT = Constants.ADVERTISE_SILENT
        self.ON_CHANGE = Constants.ADVERTISE_ON_CHANGE
        self.PERIODIC = Constants.ADVERTISE_PERIODIC

        self.url_iface = "interfaces/ifEntry"

        self.elements = {}
        self.elements['interface'] = Element(advertise=self.ON_CHANGE)
        ##################################################################

        self.periods = []
        for key, element in self.elements.items():
            if element.advertise == self.PERIODIC:
                element.period = element.period/1000
                if element.period not in self.periods:
                    self.periods.append(element.period)

        self.on_change_interval = float(ConfigurationInstance().get_on_change_interval())
        logging.debug("on_change_interval: " + str(self.on_change_interval))

        self.interfaces_old = curr_interfaces
        print("interfaces_old: " + str(len(self.interfaces_old)))
        self.interfaces_new = []
        self.interfaces_updated = []
        self.interfaces_removed = []

        self.ddController = dd_controller
        self.interfaceController = InterfaceController()
        self.interfaceParser = InterfaceParser()
Пример #8
0
 def __init__(self):
     self.policyService = PolicyService()
     self.nf_type = ConfigurationInstance().get_nf_type()
Пример #9
0
 def __init__(self):
     self.bridgeService = BridgeService()
     self.nf_type = ConfigurationInstance().get_nf_type()
Пример #10
0
 def __init__(self):
     self.arpTableService = ArpTableService()
     self.nf_type = ConfigurationInstance().get_nf_type()
Пример #11
0
 def __init__(self):
     self.nat_table_service = NatTableService()
     self.nf_type = ConfigurationInstance().get_nf_type()
Пример #12
0
 def __init__(self):
     self.blacklistService = BlacklistService()
     self.nf_type = ConfigurationInstance().get_nf_type()
Пример #13
0
 def __init__(self):
     self.iperfService = IperfService()
     self.iperfServiceNative = IperfServiceNative()
     self.nf_type = ConfigurationInstance().get_nf_type()
Пример #14
0
 def __init__(self):
     self.floatingIpService = FloatingIpService()
     self.nf_type = ConfigurationInstance().get_nf_type()
Пример #15
0
    def __init__(self,
                 vnf_name,
                 nf_type,
                 datadisk_path,
                 on_change_interval=None):

        self.monitor = None
        self.rest_port = "9010"

        ConfigurationInstance().clear_db()
        ConfigurationInstance().save_vnf_name(vnf_name)
        ConfigurationInstance().save_nf_type(nf_type)
        ConfigurationInstance().save_datadisk_path(datadisk_path)
        if on_change_interval is not None:
            on_change_interval = int(on_change_interval) / 1000
        else:
            on_change_interval = 1
        ConfigurationInstance().save_on_change_interval(on_change_interval)

        self.vnf = ConfigurationInstance().get_vnf_name()
        self.nf_type = ConfigurationInstance().get_nf_type()
        self.datadisk_path = ConfigurationInstance().get_datadisk_path()

        logging.debug("nf_type: " + self.nf_type)
        logging.debug("datadisk_path: " + self.datadisk_path)
        logging.debug("on_change_interval: " +
                      str(ConfigurationInstance().get_on_change_interval()))

        dbManager().clear_db()

        ###################################################################
        self.tenant_id = None
        self.graph_id = None
        self.vnf_id = None
        self.broker_url = None
        self.configuration_interface = None
        '''
        datadisk_path contains the path where an external volume is attached to the VNF.
        Inside such a module you can find a metadata file containing some information about the VNF
        The datadisk contains:
        - tenant keys
        - template of the VNF
        - a metadata file
        - an initial configuration the VNF has tu use at bootstrap (optional)
        '''
        assert os.path.isdir(
            self.datadisk_path) is True, "datadisk not mounted onto the VNF"
        self.tenant_keys_file = self.datadisk_path + "/tenant-keys.json"
        self.template = self.datadisk_path + "/template.json"
        self.metadata_file = self.datadisk_path + "/metadata.json"
        self.initial_configuration_path = self.datadisk_path + "/initial_configuration.json"
        assert os.path.exists(
            self.tenant_keys_file
        ) is True, "Error, tenant-keys.json file not found in datadisk"
        assert os.path.exists(
            self.template), "Error, template.json file not found in datadisk"
        assert os.path.exists(
            self.metadata_file
        ) is True, "Error, metadata.json file not found in datadisk"
        self._read_metadata_file(self.metadata_file)
        if os.path.isdir("/etc/doubledecker") is False:
            os.makedirs("/etc/doubledecker")
        tenant_keys_path = "/etc/doubledecker/" + self.tenant_id + "-keys.json"
        if os.path.exists(tenant_keys_path) is False:
            shutil.copy(self.tenant_keys_file, tenant_keys_path)

        self.configuration_interface = self._get_iface_from_template()
        logging.debug("configuration interface: " +
                      self.configuration_interface)
        ConfigurationInstance().save_iface_management(
            self.configuration_interface)

        # Add rule in the routing table to contact the broker
        #self._add_broker_rule(self.broker_url, self.configuration_interface)

        self.initial_configuration = None
        if os.path.exists(self.initial_configuration_path):
            with open(self.initial_configuration_path) as configuration:
                json_data = configuration.read()
                self.initial_configuration = json.loads(json_data)
Пример #16
0
 def __init__(self):
     self.idsService = IdsService()
     self.nf_type = ConfigurationInstance().get_nf_type()
Пример #17
0
 def __init__(self):
     self.trafficShaperService = TrafficShaperServiceWondershaper()
     self.nf_type = ConfigurationInstance().get_nf_type()
     self.traffic_shaper_map = {}
Пример #18
0
 def __init__(self):
     self.whitelistService = WhitelistService()
     self.nf_type = ConfigurationInstance().get_nf_type()
Пример #19
0
 def __init__(self):
     self.interfaceService = InterfaceService()
     self.nf_type = ConfigurationInstance().get_nf_type()
Пример #20
0
 def __init__(self):
     self.dhcpClientService = DhcpClientService()
     self.nf_type = ConfigurationInstance().get_nf_type()
Пример #21
0
 def __init__(self):
     self.natCoreService = NatCoreService()
     self.nf_type = ConfigurationInstance().get_nf_type()