예제 #1
0
    def get_acl_list(self, src=None, dst=None, firewall=None):
        """Get all acl filtered by optional parameters

        Parameters
        ----------
        src : Ip / Firewall (optional). The source of the acl any if src is not defined
        dst : Ip / Firewall (optional). The destination of the acl any if dst is not defined
        firewall : Firewall (optional). Filter acl belonging to this firewall any if firewall is not defined
        """
        acl_list = []
        if src and isinstance(src, Ip) and not self.multidigraph.has_node(src):
            src = Ip.ListContains(self.digraph_subnet_list, src)
        if dst and isinstance(dst, Ip) and not self.multidigraph.has_node(dst):
            dst = Ip.ListContains(self.digraph_subnet_list, dst)

        if src and not self.multidigraph.has_node(src):
            return acl_list

        for elem in self.multidigraph.edges(src, data=True):
            if dst and elem[1] != dst:
                continue
            if firewall and elem[2]['firewall'] != firewall:
                continue
            acl_list.append(elem[2]['acl'])

        return acl_list
예제 #2
0
    def get_all_simple_path(self, source, dest):
        """Get all simple path from a point to an other.

        Return
        ------
        Return a networkX list of path
        """
        source_node = None
        dest_node = None

        if source:
            for i in self.subnet_list:
                if Ip.ListContains([i], source):
                    source_node = i
                    break

        if dest:
            for i in self.subnet_list:
                if Ip.ListContains([i], dest):
                    dest_node = i
                    break

        if not source or not dest:
            for node in self.graph.nodes(data=True):
                if node[1]['object'].marker_type == 'from':
                    source_node = node[0]
                if node[1]['object'].marker_type == 'to':
                    dest_node = node[0]

        if not source_node or not self.multidigraph.has_node(source_node)\
                or not dest_node or not self.multidigraph.has_node(dest_node):
            raise

        return nx.all_simple_paths(self.multidigraph, source_node, dest_node)
예제 #3
0
 def add_node(obj):
     if isinstance(obj, Interface) and obj.network:
         res = Ip.ListContains(self.digraph_subnet_list, obj.network)
         if res is None:
             self.digraph_subnet_list.append(obj.network)
             self.multidigraph.add_node(obj.network)
             return obj.network
         else:
             return res
     else:
         self.multidigraph.add_node(obj)
         return obj
예제 #4
0
    def _add_interface(self, firewall, interface):
        """Find or add the network interface if it doesn't exist and link the network with firewall

        Parameters
        ----------
        firewall : Firewall. The firewall to connect.
        interface : Interface. The interface to find / add.
        """
        if interface.network:
            res = Ip.ListContains(self.subnet_list, interface.network)
            if res is None:
                self.subnet_list.append(interface.network)
                self.graph.add_node(interface.network,
                                    object=Node(interface.network))
                self.graph.add_edge(firewall,
                                    interface.network,
                                    object=Edge(interface, firewall))
            else:
                self.graph.add_edge(firewall,
                                    res,
                                    object=Edge(interface, firewall))