Search in sources :

Example 1 with DefaultControllerNode

use of org.onosproject.cluster.DefaultControllerNode in project onos by opennetworkinglab.

the class BgpSessionManagerTest method setUp.

@Before
public void setUp() throws Exception {
    peer1 = new TestBgpPeer(BGP_PEER1_ID);
    peer2 = new TestBgpPeer(BGP_PEER2_ID);
    peer3 = new TestBgpPeer(BGP_PEER3_ID);
    peers.clear();
    peers.add(peer1);
    peers.add(peer2);
    peers.add(peer3);
    // 
    // Setup the BGP Session Manager to test, and start listening for BGP
    // connections.
    // 
    bgpSessionManager = new BgpSessionManager();
    routeService = createNiceMock(RouteAdminService.class);
    replay(routeService);
    bgpSessionManager.routeService = routeService;
    ClusterService clusterService = createMock(ClusterService.class);
    expect(clusterService.getLocalNode()).andReturn(new DefaultControllerNode(NODE_ID, LOCAL)).anyTimes();
    replay(clusterService);
    bgpSessionManager.clusterService = clusterService;
    // NOTE: We use port 0 to bind on any available port
    ComponentContext componentContext = createMock(ComponentContext.class);
    getDictionaryMock(componentContext);
    replay(componentContext);
    bgpSessionManager.activate(componentContext);
    // Get the port number the BGP Session Manager is listening on
    Channel serverChannel = TestUtils.getField(bgpSessionManager, "serverChannel");
    SocketAddress socketAddress = serverChannel.getLocalAddress();
    InetSocketAddress inetSocketAddress = (InetSocketAddress) socketAddress;
    InetAddress connectToAddress = InetAddresses.forString("127.0.0.1");
    connectToSocket = new InetSocketAddress(connectToAddress, inetSocketAddress.getPort());
    // 
    // Setup the AS Paths
    // 
    ArrayList<BgpRouteEntry.PathSegment> pathSegments = new ArrayList<>();
    byte pathSegmentType1 = (byte) BgpConstants.Update.AsPath.AS_SEQUENCE;
    ArrayList<Long> segmentAsNumbers1 = new ArrayList<>();
    segmentAsNumbers1.add(65010L);
    segmentAsNumbers1.add(65020L);
    segmentAsNumbers1.add(65030L);
    BgpRouteEntry.PathSegment pathSegment1 = new BgpRouteEntry.PathSegment(pathSegmentType1, segmentAsNumbers1);
    pathSegments.add(pathSegment1);
    asPathShort = new BgpRouteEntry.AsPath(new ArrayList<>(pathSegments));
    // 
    byte pathSegmentType2 = (byte) BgpConstants.Update.AsPath.AS_SET;
    ArrayList<Long> segmentAsNumbers2 = new ArrayList<>();
    segmentAsNumbers2.add(65041L);
    segmentAsNumbers2.add(65042L);
    segmentAsNumbers2.add(65043L);
    BgpRouteEntry.PathSegment pathSegment2 = new BgpRouteEntry.PathSegment(pathSegmentType2, segmentAsNumbers2);
    pathSegments.add(pathSegment2);
    // 
    asPathLong = new BgpRouteEntry.AsPath(pathSegments);
}
Also used : ComponentContext(org.osgi.service.component.ComponentContext) InetSocketAddress(java.net.InetSocketAddress) Channel(org.jboss.netty.channel.Channel) ArrayList(java.util.ArrayList) RouteAdminService(org.onosproject.routeservice.RouteAdminService) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) ClusterService(org.onosproject.cluster.ClusterService) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) InetAddress(java.net.InetAddress) Before(org.junit.Before)

Example 2 with DefaultControllerNode

use of org.onosproject.cluster.DefaultControllerNode in project onos by opennetworkinglab.

the class ControllerNodeCodec method decode.

@Override
public ControllerNode decode(ObjectNode json, CodecContext context) {
    checkNotNull(json, "JSON cannot be null");
    String ip = json.path("ip").asText();
    return new DefaultControllerNode(new NodeId(json.path("id").asText(ip)), IpAddress.valueOf(ip), json.path("tcpPort").asInt(DEFAULT_PORT));
}
Also used : NodeId(org.onosproject.cluster.NodeId) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode)

Example 3 with DefaultControllerNode

use of org.onosproject.cluster.DefaultControllerNode in project onos by opennetworkinglab.

the class SimpleClusterStore method activate.

@Activate
public void activate() {
    instance = new DefaultControllerNode(new NodeId("local"), LOCALHOST);
    listenerRegistry = new ListenerRegistry<>();
    eventDispatcher.addSink(WorkPartitionEvent.class, listenerRegistry);
    log.info("Started");
}
Also used : NodeId(org.onosproject.cluster.NodeId) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) Activate(org.osgi.service.component.annotations.Activate)

Example 4 with DefaultControllerNode

use of org.onosproject.cluster.DefaultControllerNode in project onos by opennetworkinglab.

the class SimpleMastershipStore method activate.

@Activate
public void activate() {
    if (clusterService == null) {
        // just for ease of unit test
        final ControllerNode instance = new DefaultControllerNode(new NodeId("local"), IpAddress.valueOf("127.0.0.1"));
        clusterService = new ClusterService() {

            private final Instant creationTime = Instant.now();

            @Override
            public ControllerNode getLocalNode() {
                return instance;
            }

            @Override
            public Set<ControllerNode> getNodes() {
                return ImmutableSet.of(instance);
            }

            @Override
            public Set<Node> getConsensusNodes() {
                return ImmutableSet.of();
            }

            @Override
            public ControllerNode getNode(NodeId nodeId) {
                if (instance.id().equals(nodeId)) {
                    return instance;
                }
                return null;
            }

            @Override
            public State getState(NodeId nodeId) {
                if (instance.id().equals(nodeId)) {
                    return State.ACTIVE;
                } else {
                    return State.INACTIVE;
                }
            }

            @Override
            public Version getVersion(NodeId nodeId) {
                if (instance.id().equals(nodeId)) {
                    return versionService.version();
                }
                return null;
            }

            @Override
            public Instant getLastUpdatedInstant(NodeId nodeId) {
                return creationTime;
            }

            @Override
            public void addListener(ClusterEventListener listener) {
            }

            @Override
            public void removeListener(ClusterEventListener listener) {
            }
        };
    }
    log.info("Started");
}
Also used : ClusterService(org.onosproject.cluster.ClusterService) HashSet(java.util.HashSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) Version(org.onosproject.core.Version) State(org.onosproject.cluster.ControllerNode.State) Instant(java.time.Instant) NodeId(org.onosproject.cluster.NodeId) ControllerNode(org.onosproject.cluster.ControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) ClusterEventListener(org.onosproject.cluster.ClusterEventListener) Activate(org.osgi.service.component.annotations.Activate)

Example 5 with DefaultControllerNode

use of org.onosproject.cluster.DefaultControllerNode in project onos by opennetworkinglab.

the class DefaultClusterMetadataProvider method activate.

@Activate
public void activate() {
    String localIp = getSiteLocalAddress();
    ControllerNode localNode = new DefaultControllerNode(new NodeId(localIp), IpAddress.valueOf(localIp), DEFAULT_ONOS_PORT);
    ClusterMetadata metadata = new ClusterMetadata(PROVIDER_ID, "default", localNode, ImmutableSet.of(), ImmutableSet.of(), UUID.randomUUID().toString());
    long version = System.currentTimeMillis();
    cachedMetadata.set(new Versioned<>(metadata, version));
    providerRegistry.register(this);
    log.info("Started");
}
Also used : ClusterMetadata(org.onosproject.cluster.ClusterMetadata) NodeId(org.onosproject.cluster.NodeId) ControllerNode(org.onosproject.cluster.ControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) Activate(org.osgi.service.component.annotations.Activate)

Aggregations

DefaultControllerNode (org.onosproject.cluster.DefaultControllerNode)11 NodeId (org.onosproject.cluster.NodeId)9 ControllerNode (org.onosproject.cluster.ControllerNode)7 Activate (org.osgi.service.component.annotations.Activate)5 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)3 ClusterMetadata (org.onosproject.cluster.ClusterMetadata)3 Sets (com.google.common.collect.Sets)2 InetAddress (java.net.InetAddress)2 URL (java.net.URL)2 Instant (java.time.Instant)2 List (java.util.List)2 Test (org.junit.Test)2 ClusterMetadataProvider (org.onosproject.cluster.ClusterMetadataProvider)2 ClusterMetadataProviderRegistry (org.onosproject.cluster.ClusterMetadataProviderRegistry)2 ClusterMetadataProviderService (org.onosproject.cluster.ClusterMetadataProviderService)2 ClusterService (org.onosproject.cluster.ClusterService)2 ClusterServiceAdapter (org.onosproject.cluster.ClusterServiceAdapter)2 Node (org.onosproject.cluster.Node)2 PartitionId (org.onosproject.cluster.PartitionId)2