Exemplo n.º 1
0
    def get_edge_list_by_node(self, edge_type, node):
        """
                Get the edges connected with specified node in a given direction
                If the input edge_type is DIRECTED then graph is asymmetric
                If the edge_type is UNDIRECTED then graph is symmetric
        
                @param edge_type: The direction  of the edge
                @type edge_type : L{Enum<onep.topology.Enum>}
        
                @param node: The node of interest. The Node object
                must contain the node name
                @type node: L{Node<onep.topology.Node>}
        
                @return: A list of Edges. If no match found empty list is returned
                @rtype: C{list} of L{Edge<onep.topology.Edge>}
                """
        validate(node, Node)
        if not isValidEnum(Edge.EdgeType, edge_type):
            raise OnepIllegalArgumentException('edge_type is invalid')
        edge_list = []
        for edge in self._edge_map.values():
            if node.name == edge._head_node.name and node.address_list is not None and edge._head_node.address_list is not None and set(node.address_list) == set(edge._head_node.address_list):
                edge_list.append(edge)
            if node.name == edge._tail_node.name and node.address_list is not None and edge._tail_node.address_list is not None and set(node.address_list) == set(edge._tail_node.address_list):
                edge_list.append(edge)

        if edge_type == Edge.EdgeType.DIRECTED:
            return edge_list
        else:
            return self._convert_to_undirected_edge_list(edge_list)
Exemplo n.º 2
0
def _from_idl(attr_idl, network_element):
    """For internal use only"""
    if attr_idl == None:
        return
    attr = None
    attrName = None
    if not network_element.is_connected():
        log.debug('Application is not connected to network element ' +
                  network_element.host_address)
        return
    if network_element.session_handle == None:
        log.debug('Application is not connected to network element ' +
                  network_element.host_address)
        return
    format = attr_idl.format
    attr_type = attr_idl.type
    if not isValidEnum(OnepAAAAttributeType, attr_type):
        raise OnepException('Error in attr type ' + str(attr_type))
    if attr_idl.type == OnepAAAAttributeType.ONEP_AAA_AT_APP_ATTR:
        app_attr_value = attr_idl.str_value
        if app_attr_value.startswith('"') and app_attr_value.endswith('"'):
            app_attr_value = app_attr_value.substring[1:-1]
        app_value = app_attr_value.split(':')
        if len(app_value) < 3:
            raise OnepException('Invalid app attribute format ' +
                                str(app_value))
        attrName = app_value[0]
        try:
            if app_value[1].lower() == 'string':
                attr = StringAttribute(attr_type, attrName, app_value[2])
            else:
                attr = IntAttribute(attr_type, attrName, int(app_value[2]))
        except OnepIllegalArgumentException as e:
            raise OnepException(
                'Error adding a Application attribute type ' + str(app_value),
                e)
    else:
        result = {
            AttrFormat_e.AAA_TYPE_FORMAT_ULONG:
            lambda _type, _idl: IntAttribute(_type, None, _idl.ulong_value),
            AttrFormat_e.AAA_TYPE_FORMAT_STRING:
            lambda _type, _idl: StringAttribute(_type, None, _idl.str_value),
            AttrFormat_e.AAA_TYPE_FORMAT_BINARY:
            lambda _type, _idl: BinaryAttribute(_type, None, _idl.binary_value
                                                ),
            AttrFormat_e.AAA_TYPE_FORMAT_IP_ADDR:
            lambda _type, _idl: BinaryAttribute(_type, None, _idl.binary_value
                                                ),
            AttrFormat_e.AAA_TYPE_FORMAT_IPV6_ADDR:
            lambda _type, _idl: BinaryAttribute(_type, None, _idl.binary_value)
        }
        attr = result[format](attr_type, attr_idl)
        if attr == None:
            raise OnepException('Unsupported Attribute Format')
    return attr
Exemplo n.º 3
0
    def __init__(self, name, type, address_list):
        """
        @raise OnepIllegalArgumentException: The exception is thrown when
        address received in the address list is None or invalid.
        """
        validate(name, str)
        if isValidEnum(self.NodeType, type) is False:
            raise OnepIllegalArgumentException('type is invalid.')
        validate(address_list, list)
        for addr in address_list:
            validate(addr, str)

        self._name = name
        self._type = type
        self._address_list = address_list
        self.mt_node = None
Exemplo n.º 4
0
    def __init__(self, name, type, node, address_list):
        """
        Constructor For internal use only
        @raise OnepIllegalArgumentException: The exception is thrown if
        any of the input argument is invalid.
        """
        validate(name, str)
        if isValidEnum(self.NodeConnectorType, type) is False:
            raise OnepIllegalArgumentException('type is invalid.')
        if not isinstance(node, Node):
            raise OnepIllegalArgumentException('node is invalid.')
        validate(address_list, list)
        for addr in address_list:
            validate(addr, str)

        self._node = node
        self._name = name
        self._type = type
        self._address_list = address_list
Exemplo n.º 5
0
 def get_edge_list(self, edge_type):
     """
             Get the list of edges based on the directionality in a grpah
             The method returns a set of edges based on the direction requested
             if DIRECTED edges are requested then the edges to/from Node A and Node B
             are treated as different edges and both edges are returned.
             If UNDIRECTED edges are requested then the graph is assumed symmetric
             and only one edge in this case is returned
     
             @param edge_type: Type of edge either DIRECTED or UNDIRECTED. If the input
             is None, default type DIRECTED will be used
             @type edge_type: C{list} of L{Edge<onep.topology.Edge>}
             """
     if not isValidEnum(Edge.EdgeType, edge_type):
         raise OnepIllegalArgumentException('edge_type is invalid')
     if edge_type == None or edge_type == Edge.EdgeType.DIRECTED:
         return self._edge_map.values()
     else:
         return self._convert_to_undirected_edge_list(self._edge_map.values())
Exemplo n.º 6
0
 def __init__(self, start_prefix, range_type, count):
     """
             Create the range tuple (Start L3 Unicast Prefix, Range Type, Count)
             used for filtering.
     
             If range type is EQUAL_OR_LARGER, then the range indicates Count
             routes starting with the prefix equal or lexically larger than
             Start Prefix.
     
             If range type is ROUTING_ROUTE_RANGE_LARGER, then the filter
             indicates Count routes starting with the prefix lexically
             larger than Start Prefix.
     
             If count is 0, it is treated as no count limit and all routes
             matching the (Start L3 Unicast Prefix, Range Type) are included.
     
             @param start_prefix:
                     The starting prefix reference of the range.
             @type start_prefix: L{NetworkPrefix<onep.interfaces.NetworkPrefix>}
             @param range_type:
                     Indicate if the range include the start prefix.
             @type range_type: L{RouteRange.RangeType<onep.routing.RouteRange>}
             @param count:
                        Maximum number of route the range should cover.
                        A count of 0 means no limit.
             @type count: C{int}
             """
     super(L3UnicastRouteRange, self).__init__()
     if not isinstance(start_prefix, NetworkPrefix):
         raise OnepIllegalArgumentException('start_prefix', 'Invalid type')
     if not isValidEnum(RouteRange.RangeType, range_type):
         raise OnepIllegalArgumentException('range_type', 'Invalid type')
     if count < 0 or not isinstance(count, int):
         raise OnepIllegalArgumentException('count', 'Invalid type')
     self._start_prefix = start_prefix
     self._range_type = range_type
     self._count = count
Exemplo n.º 7
0
 def _set_range_type(self, range_type):
     if not isValidEnum(RouteRange.RangeType, range_type):
         raise OnepIllegalArgumentException('range_type', 'Invalid type')
     self._range_type = range_type
Exemplo n.º 8
0
    def update(self, event_type, list):
        """
                Updates the topology graph object with a list of objects passed,
                based on the topology change events. If the event is:
        
                ONEP_TOPOLOGY_EDGES_ADD - The list should contain a set of EDGE object
                that needs to be added to the graph object.
        
                ONEP_TOPOLOGY_EDGES_DELETE - The list should contain a set of EDGE
                objects that needs to be removed from the graph object.
        
                ONEP_TOPOLOGY_NODES_ADD - The list should contain a set of nodes that
                needs to be added to the graph object.
        
                ONEP_TOPOLOGY_NODES_DELETE - The list should contain a set of
                nodes that needs to be remove to the graph object.
                Removing a node from a graph would also result in removing
                all IN bound and OUT bound edges associated with the node.
        
                Note:
                Adding a node to a graph would only reflect in the output of
                get_node_list() method, and the node remains orphaned.
        
                @param event_type: Type of topology change event.
                @type event_type: L{enum<onep.core.util.Enum>}
                @param list: List of edges or nodes that needs to be updated based on
                @type list: C{list}
        
                @raise OnepIllegalArgumentException: The exception is thrown when the
                input list contains wrong type of element.
                """
        from onep.topology.TopologyEvent import TopologyEvent
        if isValidEnum(TopologyEvent.TopologyEventType, event_type) is False:
            raise OnepIllegalArgumentException('event_type is invalid.')
            return 
        validate(list, type([]))
        if event_type == TopologyEvent.TopologyEventType.EDGES_ADD:
            for obj in list:
                if not isinstance(obj, Edge):
                    raise OnepIllegalArgumentException('Edge is invalid.')
                with self._lock:
                    self._edge_map[str(obj)] = obj
                    self._add_to_index(obj)

            return 
        if event_type == TopologyEvent.TopologyEventType.EDGES_DELETE:
            for obj in list:
                if not isinstance(obj, Edge):
                    raise OnepIllegalArgumentException('Edge is invalid.')
                with self._lock:
                    if self._edge_map.has_key(str(obj)):
                        self._log.debug('update1 removing edge ' + str(obj))
                        del self._edge_map[str(obj)]
                        self._remove_from_index(obj)
                    else:
                        edge_to_remove = self._get_matching_edge_from_map(obj)
                        if edge_to_remove:
                            self._log.debug('update2 removing edge ' + str(edge_to_remove))
                            del self._edge_map[str(edge_to_remove)]
                            self._remove_from_index(edge_to_remove)

            return 
        if event_type == TopologyEvent.TopologyEventType.NODES_ADD:
            for obj in list:
                if not isinstance(obj, Node):
                    raise OnepIllegalArgumentException('Node is invalid.')
                with self._lock:
                    self._node_map[str(obj)] = obj

            return 
        if event_type == TopologyEvent.TopologyEventType.NODES_DELETE:
            for obj in list:
                if not isinstance(obj, Node):
                    raise OnepIllegalArgumentException('Node is invalid.')
                edge_list = self.get_edge_list_by_node(Edge.EdgeType.DIRECTED, obj)
                for edge in edge_list:
                    with self._lock:
                        if self._edge_map.has_key(str(edge)):
                            self._log.debug('update ND removing edge ' + str(edge))
                            del self._edge_map[str(edge)]
                            self._remove_from_index(edge)
                            break
                        else:
                            edge_to_remove = self._get_matching_edge_from_map(edge)
                            if edge_to_remove:
                                self._log.debug('update ND2 removing edge ' + str(edge_in_map))
                                del self._edge_map[str(edge_in_map)]
                                self._remove_from_index(edge_in_map)
                                break

                with self._lock:
                    if self._node_map.has_key(str(obj)):
                        self._log.debug('update2 removing node ' + str(obj))
                        del self._node_map[str(obj)]

            return