def __init__(self, **kwargs): super().__init__(name="Agent") self.addresses = [] utils3.set_attributes(self, override=True, **kwargs) self.loading = asyncio.Event() self.loading.set() self.restarting = False
def __init__(self, **kwargs): default_values = { "host": "127.0.0.1", "login": "******", "loop": None, "password": "******", "virtualhost": "/", "port": None, "ssl": False, "transport": None, "protocol": None, "channel": None, "bind_action_queue": False, "heartbeat_receive_key": AMQP_KEY_HEARTBEATS_CTRL, "heartbeat_callback": no_op_callback, "action_callback": no_op_callback } #Initialize the agent utils3.set_attributes(self, override=False, **default_values) utils3.set_attributes(self, override=True, **kwargs) if self.port is None: if self.ssl: self.port = 5671 else: self.port = 5672 #Synchronization elements self.connect_lock = asyncio.Lock() self.connected = asyncio.Event() #Update the runtime ID self.modify_runtime_id_hb_payload()
def init_mptcp(self, **kwargs): utils3.set_attributes(self, override=True, **kwargs) del_flow(self.dp_mptcp, strict=False) add_flow(self.dp_mptcp, "table={}, priority=0,".format(TABLE_START), "actions=goto_table:{}".format(TABLE_MPTCP_VLAN)) add_flow(self.dp_mptcp, "table={}, priority=10,".format(TABLE_START), "in_port={},".format(self.patch_mptcp_port), "actions=goto_table:{}".format(TABLE_MPTCP_LEARN)) add_flow(self.dp_mptcp, "table={},".format(TABLE_MPTCP_LEARN), "priority=10, tcp,", "actions=goto_table:{}".format(TABLE_MPTCP_FORWARD)) add_flow( self.dp_mptcp, "table={},".format(TABLE_MPTCP_LEARN), "priority=10, arp,", "actions=learn(table={}, priority=10,".format(TABLE_MPTCP_LEARNT), "eth_src=E1:8E:36:8C:F6:0D, eth_type=0x0800,", "NXM_OF_IP_DST[]=NXM_OF_ARP_SPA[],", "load:NXM_NX_ARP_SHA[]->NXM_OF_ETH_DST[],", "output:NXM_OF_IN_PORT[])") add_flow(self.dp_mptcp, "table={},".format(TABLE_MPTCP_LEARN), "priority=0, actions=drop") add_flow(self.dp_mptcp, "table={},".format(TABLE_MPTCP_VLAN), "priority=0, actions=drop") add_flow(self.dp_mptcp, "table={},".format(TABLE_MPTCP_LEARNT), "priority=0, actions=drop") add_flow(self.dp_mptcp, "table={},".format(TABLE_MPTCP_FORWARD), "priority=0, actions=drop") add_flow(self.dp_tun, "table={}, priority=10,".format(TABLE_START), "in_port={},".format(self.patch_tun_port_mptcp), "actions=goto_table:{}".format(TABLE_IN_MPTCP)) add_flow(self.dp_tun, "table={}, priority=0,".format(TABLE_IN_MPTCP), "actions=drop")
def __init__(self, **kwargs): self.node_id = str(uuid.uuid4()) utils3.set_attributes(self, override=True, **kwargs) super().__init__(name="L2_tunnel") utils3.set_attributes(self, override=False, status="Pending", deleting=False)
def __init__(self, **kwargs): utils3.set_attributes(self, override=True, **kwargs) self.tunnels_port_ids = {} self.tunnels = {} self.networks_mapping = {} self.networks = {} self.expansions = {} self.update_runtime_id()
def __init__(self, **kwargs): self.node_id = str(uuid.uuid4()) self.applied = False utils3.set_attributes(self, override=True, **kwargs) super().__init__(name="Expansion") utils3.set_attributes(self, override=False, status="Pending", deleting=False)
def __init__(self, **kwargs): utils3.set_attributes(self, override=True, **kwargs) #If MPTCP is disabled, do nothing when called if not self.enabled: self.add_proxy = no_op self.del_proxy = no_op return self.ipr = pyroute_utils.createIpr() self.networks = {} self.proxies = {} #Get the available internal IP addresses to use on the Lan side self.available_internal_ips = set(self.internal_net.hosts()) self.internal_netmask = self.internal_net.prefixlen #Internal gateway is a fake gateway used to send all traffic to #using a static arp entry. the mac addresses are then rewritten by the #switch self.internal_gateway = self.get_next_addr_int() #Parse the network configuration file with open(self.mptcp_conf_path, "r") as file: network_configs = json.load(file) self.routing_table_id = 100 #For each network in the config for network_config in network_configs: #Detect duplicates based on external interface if network_config["external_interface"] in self.networks: raise ValueError("Duplicated MPTCP network name") #Initialize the MPTCP network mptcp_net = Mptcp_network(ipr=self.ipr, routing_table_id=self.routing_table_id, **network_config) self.routing_table_id += 1 self.networks[mptcp_net.external_interface] = mptcp_net #Create the switch infrastructure on lan side self.ovs_manager.set_infra_mptcp(self.dp_mptcp) #Create the Jinja2 environments for the shadowsocks configuration files, #for ss-redir self.redir_template_folder, self.redir_template_file = os.path.split( self.template_redir) self.redir_env = Environment(autoescape=False, loader=FileSystemLoader( self.redir_template_folder), trim_blocks=False) #for ss-server self.server_template_folder, self.server_template_file = os.path.split( self.template_server) self.server_env = Environment(autoescape=False, loader=FileSystemLoader( self.server_template_folder), trim_blocks=False)
def __init__(self, **kwargs): self._logger = logging.getLogger('DNSCallbacks') self._dns_timeout = {None:[0]} # Default single blocking query utils3.set_attributes(self, **kwargs) self.loop = asyncio.get_event_loop() self.state = {} self.soa_list = [] self.resolver_list = [] self.registry = {} self.activequeries = {}
def __init__(self, name='ConnectionLegacy', **kwargs): """ Initialize as a ContainerNode. @param name: A description of the object. @type name: String @param private_ip: Private IPv4 address. @type private_ip: String @param private_port: Private port number. @type private_port: Integer @param outbound_ip: Outbound IPv4 address. @type outbound_ip: String @param outbound_port: Outbound port number. @type outbound_port: Integer @param remote_ip: Remote IPv4 address. @type remote_ip: String @param remote_port: Remote port number. @type remote_port: Integer @param protocol: Protocol number. @type protocol: Integer @param fqdn: Allocating FQDN. @type fqdn: String @param dns_resolver: IPv4 address of the DNS server. @type dns_resolver: String @param dns_host: IPv4 address of the DNS client. @type dns_host: String @param timeout: Time to live (sec). @type timeout: Integer or float """ super().__init__(name) # Set default values self.autobind = True self._autobind_flag = False self.dns_bind = False # Set attributes utils3.set_attributes(self, override=True, **kwargs) # Set default values of unset attributes attrlist_zero = [ 'private_ip', 'private_port', 'outbound_ip', 'outbound_port', 'remote_ip', 'remote_port', 'protocol', 'loose_packet' ] attrlist_none = [ 'fqdn', 'dns_resolver', 'dns_host', 'host_fqdn', 'timeout' ] utils3.set_default_attributes(self, attrlist_zero, 0) utils3.set_default_attributes(self, attrlist_none, None) # Set default timeout if not overriden if not self.timeout: self.timeout = ConnectionLegacy.TIMEOUT # Take creation timestamp self.timestamp_zero = time.time() ## Override timeout ## #self.timeout = 600.0 ###################### self.timestamp_eol = self.timestamp_zero + self.timeout self._build_lookupkeys()
def __init__(self, name='HostEntry', **kwargs): """ Initialize as a ContainerNode """ super().__init__(name) # Initialize services dictionary self.services = {} self.ipv4 = None self.fqdn = None utils3.set_attributes(self, override=True, **kwargs) # Sanitize key in dictionary for lookupkeys() self.services.setdefault(KEY_SERVICE_SFQDN, []) # Normalize SFQDN service definition self._normalize_service_sfqdn() # Create hostname by splitting FQDN name self.hostname = self.fqdn.split('.')[0]
def __init__(self, name='DataRepository', **kwargs): """ Initialize """ self._logger = logging.getLogger(name) self.configfile = None self.configfolder = None self.policyfile = None self.policyfolder = None self.api_url = None utils3.set_attributes(self, override=True, **kwargs) self._cached_policy_host = None self._cached_policy_ces = None self._reload_policies() # Initiate HTTP session with PolicyDatabase self.rest_api_init()
def __init__(self, **kwargs): utils3.set_attributes(self, override=True, **kwargs) self.ext_addresses = {}
def __init__(self, **kwargs): self._logger = logging.getLogger('PacketCallbacks') utils3.set_attributes(self, **kwargs)
def __init__(self, **kwargs): utils3.set_attributes(self, override=True, **kwargs) self.nated = True #Attributes of interest: # - gateway : the gateway IP address for the mptcp namespace # - network : the network from which the pool of IP comes from # - net_mask : the network mask # - external_ip : the IP of the host in the external network # - external_interface : the host interface (from config) # - gateway_address : the external gateway address from config file #Create a bridge for that network self.bridge_idx = pyroute_utils.createLink( self.ipr, "br-{}".format(self.external_interface), "bridge") pyroute_utils.setUp(self.ipr, idx=self.bridge_idx) #Get the usable range of IP addresses network = ipaddress.ip_network(self.address_range) self.available_addresses = set(network.hosts()) #get the external IP and the mask external_ip_masked = pyroute_utils.get_ip_with_mask( self.ipr, self.external_interface).pop() self.external_ip = ipaddress.ip_address( external_ip_masked.split("/")[0]) net_if_idx = pyroute_utils.getLink(self.ipr, self.external_interface) #If the MPTCP network is nated if self.nated: #Define the nated network characteristics self.gateway = self.get_next_addr() self.net_mask = network.prefixlen self.network = ipaddress.ip_network("{}/{}".format( self.gateway, self.net_mask), strict=False) #get the external network (for routing purpose) gw_network = ipaddress.ip_network(external_ip_masked, strict=False) # add the masquerade rule on ext interface iptables.addRules( iptables.def_masquerade([self.external_interface])) #Add an ip rule for traffic from network to use source routing try: pyroute_utils.del_rule(self.ipr, table=self.routing_table_id, src=self.network.with_prefixlen) except: pass pyroute_utils.add_rule(self.ipr, table=self.routing_table_id, src=self.network.with_prefixlen) #Set the address on the bridge pyroute_utils.flush_addresses(self.ipr, self.bridge_idx) pyroute_utils.add_address(self.ipr, self.bridge_idx, self.gateway.exploded, self.net_mask) #populate the routing table, the routes for both links and the default pyroute_utils.flush_routes(self.ipr, table=self.routing_table_id) pyroute_utils.add_route( self.ipr, dst=gw_network.with_prefixlen, proto="static", scope="link", prefsrc=self.external_ip.exploded, table=self.routing_table_id, oif=net_if_idx, ) pyroute_utils.add_route(self.ipr, gateway=self.gateway_address, table=self.routing_table_id) pyroute_utils.add_route( self.ipr, dst=self.network.with_prefixlen, proto="static", scope="link", prefsrc=self.gateway.exploded, table=self.routing_table_id, oif=self.bridge_idx, ) #If not nated else: #Get the network characteristics self.network = ipaddress.ip_network(external_ip_masked, stric=False) self.gateway = ipaddress.ip_address(self.gateway_address) self.net_mask = self.network.prefixlen #Remove the ip from the interface to add it on the bridge pyroute_utils.del_address(self.ipr, net_if_idx, self.external_ip.exploded, self.net_mask) pyroute_utils.flush_addresses(self.ipr, self.bridge_idx) pyroute_utils.add_address(self.ipr, self.bridge_idx, self.external_ip.exploded, self.net_mask) #Bridge the interface pyroute_utils.addIfBr(self.ipr, ifIdx=net_if_idx, brIdx=self.bridge_idx)
def update(self, **kwargs): utils3.set_attributes(self, override=True, **kwargs)
def __init__(self, **kwargs): self.controller_ip = None self.controller_port = None utils3.set_attributes(self, override=True, **kwargs)
def __init__(self, **kwargs): self.node_id = str(uuid.uuid4()) utils3.set_attributes(self, override=True, **kwargs) super().__init__(name="Ipsec_policy")
def __init__(self, **kwargs): self.node_id = str(uuid.uuid4()) self.agents_deployed = set() utils3.set_attributes(self, override=True, **kwargs) super().__init__(name="Network")
def __init__(self, **kwargs): utils3.set_attributes(self, override=True, **kwargs)