示例#1
0
    def __init__(self, debug=False):
        super(NetworkTopology, self).__init__()

        # name
        self.name = 'unnamed'

        # initialize logging
        self.debug = debug
        self.logger = get_logger('NetworkTopology', 'DEBUG' if debug else 'INFO')

        # dataplane engine that computes forwarding and dominator graphs
        self.dp_engine = None

        # dict of router name to router
        self.routers = dict()

        # mapping of router and interface to the next hop router
        self.next_hops = defaultdict(dict)

        # dict of all subnets in network to router and interface name directly on that subnet
        self.subnets = defaultdict(PyTricia)

        # dict of dst subnet to edges which are blocked by simple ACLs
        self.simple_acls = PyTricia()

        self.links = list()
示例#2
0
    def __init__(self,
                 netenv,
                 max_num_samples=None,
                 seed=None,
                 use_provided_samples=False,
                 fwd_state_based=False,
                 debug=False):
        self.debug = debug
        self.logger = get_logger('Sampler', 'DEBUG' if debug else 'INFO')

        self.fwd_state_based = fwd_state_based

        self.sample_random = random.Random(seed)

        self.netenv = netenv
        self.total_samples = netenv.num_concrete_envs

        self.use_provided_samples = use_provided_samples

        self.used_samples = 0
        self.used_concrete_envs = set()

        self.next_sample_in_order = 0

        if max_num_samples is not None:
            self.max_num_samples = min(max_num_samples, self.total_samples)
        else:
            self.max_num_samples = self.total_samples
示例#3
0
    def __init__(self):
        super(ForwardingTable, self).__init__()

        # initialize logging
        self.logger = get_logger('FECFinder', 'INFO')

        # init Trie
        self.fib = PyTricia()
示例#4
0
    def __init__(self):
        super(FECFinder, self).__init__()

        # initialize logging
        self.logger = get_logger('FECFinder', 'INFO')

        # init Trie
        self.root = TrieNode('')
        self.max_depth = 32

        self.prefixes = set()
示例#5
0
    def __init__(self, network, waypoints=None, debug=False):

        # initialize logging
        self.debug = debug
        self.logger = get_logger("PolicyGuesser", 'DEBUG' if debug else 'INFO')

        # load network
        self.network = network

        # only use waypoints if they are specified by the user
        if not waypoints:
            waypoints = list()
        self.waypoints = waypoints
示例#6
0
    def __init__(self, network, waypoints=None, debug=False):
        # initialize logging
        self.debug = debug
        self.logger = get_logger("PolicyDB", "DEBUG" if debug else "INFO")

        self.init = False

        self.policy_guesser = PolicyGuesser(network, waypoints=waypoints, debug=debug)
        self.keys = ["type", "subnet", "specifics", "source"]

        self.policies = None  # dataframe with the columns - type, src, dst, specifics, policy status, environments
        self.previous_size = -1  # stores the size of the current policy guess

        self.tmp_state = None
示例#7
0
    def __init__(self, nodes, next_hops, simple_acls, fib_path, debug=False):
        self.debug = debug
        self.logger = get_logger("BatfishEngine", "DEBUG" if debug else "INFO")

        # topology information
        self.nodes = nodes
        self.next_hops = next_hops
        self.simple_acls = simple_acls

        self.forwarding_graphs = defaultdict(nx.DiGraph)
        self.dominator_graphs = defaultdict(nx.DiGraph)

        # path to the directory where batfish writes the FIBs to
        self.fib_path = fib_path
示例#8
0
    def __init__(self, query, ms_response, debug=False):
        self.logger = get_logger('Response', 'DEBUG' if debug else 'INFO')

        self.type = query.type
        self.sources = query.sources
        self.destination = query.destination
        self.subnet = query.destination.subnet
        self.specifics = query.specifics
        self.netenv = query.environment

        self.counter_example = None
        self.result = list()

        self.parse_response(ms_response)
示例#9
0
    def __init__(self):
        super(EquivalenceClass, self).__init__()

        # initialize logging
        self.logger = get_logger('EquivalenceClass', 'INFO')

        # first and last address of the equivalence class
        self.first = None
        self.last = None

        # maximum number of bits in an address
        self.max_length = 32

        # needed for the iterator to keep track of the current ip address
        self.current = 0
示例#10
0
    def __init__(self,
                 base_path,
                 scenario_name,
                 config_path,
                 url="http://localhost",
                 port=8192,
                 debug=False):
        self.logger = get_logger("MinesweeperBackend",
                                 "DEBUG" if debug else "INFO")

        self.base_path = base_path

        self.scenario_name = scenario_name
        self.config_path = config_path

        self.base_url = '%s:%d' % (url, port)

        self.init = False
示例#11
0
    def __init__(self, name):
        self.name = name
        self.acl_entries = list()

        # initialize logging
        self.logger = get_logger('AccessList', 'INFO')
import os
import re


from collections import defaultdict


from config2spec.topology.builder.builder import TopologyBuilder
from config2spec.topology.topology import NetworkTopology
from config2spec.topology.interface import Interface
from config2spec.topology.access_list import AccessList
from config2spec.utils.logger import get_logger


# initialize logging
logger = get_logger('ConfigTopologyGenerator', 'INFO')


class BackendTopologyBuilder(TopologyBuilder):
    @staticmethod
    def build_topology(files, scenario_path):
        assert isinstance(files, dict) and "interfaces" in files and "acls" in files and "topology" in files

        interface_path = os.path.join(scenario_path, files["interfaces"])
        all_interfaces = BackendTopologyBuilder.parse_interfaces(interface_path)

        acls_path = os.path.join(scenario_path, files["acls"])
        all_access_lists = BackendTopologyBuilder.parse_acls(acls_path)

        topology_path = os.path.join(scenario_path, files["topology"])
        routers, edges = BackendTopologyBuilder.parse_topology(topology_path)
示例#13
0
#!/usr/bin/env python
# Author: Ruediger Birkner (Networked Systems Group at ETH Zurich)

from collections import defaultdict

from config2spec.topology.access_list import ACLType
from config2spec.utils.logger import get_logger

# initialize logging
logger = get_logger("TopologyBuilder", "INFO")


class TopologyBuilder(object):
    @staticmethod
    def auto_add_links(topology):
        """
        automatically add links between all router interfaces that are defined on the same subnet. only add a link
        if there are exactly two interfaces on that subnet.
        """
        interface_matching = defaultdict(list)

        for router_name, router in topology.routers.items():
            for intf_name, interface in router.interfaces.items():
                interface_matching[interface.subnet.network].append(
                    (router_name, intf_name))

        for subnet, names in interface_matching.items():
            if len(names) == 2:
                r1_name, r1_intf_name = names[0]
                r1_cost = topology.routers[r1_name].interfaces[
                    r1_intf_name].ospf_cost