Search in sources :

Example 1 with ClusterService

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

the class RouteManager method activate.

@Activate
protected void activate() {
    routeMonitor = new RouteMonitor(this, clusterService, storageService);
    routeResolver = new RouteResolver(this, hostService);
    threadFactory = groupedThreads("onos/route", "listener-%d", log);
    hostEventExecutors = new PredictableExecutor(DEFAULT_BUCKETS, groupedThreads("onos/route-manager", "event-host-%d", log));
    resolvedRouteStore = new DefaultResolvedRouteStore();
    routeStore.setDelegate(delegate);
    hostService.addListener(hostListener);
    routeStore.getRouteTables().stream().flatMap(id -> routeStore.getRoutes(id).stream()).forEach(routeSet -> routeResolver.resolve(routeSet));
}
Also used : Route(org.onosproject.routeservice.Route) Host(org.onosproject.net.Host) RouteStore(org.onosproject.routeservice.RouteStore) PredictableExecutor(org.onlab.util.PredictableExecutor) LoggerFactory(org.slf4j.LoggerFactory) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) RouteEvent(org.onosproject.routeservice.RouteEvent) HostListener(org.onosproject.net.host.HostListener) HostService(org.onosproject.net.host.HostService) RouteStoreDelegate(org.onosproject.routeservice.RouteStoreDelegate) Component(org.osgi.service.component.annotations.Component) StorageService(org.onosproject.store.service.StorageService) ImmutableList(com.google.common.collect.ImmutableList) RouteAdminService(org.onosproject.routeservice.RouteAdminService) Map(java.util.Map) HostEvent(org.onosproject.net.host.HostEvent) Activate(org.osgi.service.component.annotations.Activate) ThreadFactory(java.util.concurrent.ThreadFactory) ExecutorService(java.util.concurrent.ExecutorService) IpAddress(org.onlab.packet.IpAddress) RouteService(org.onosproject.routeservice.RouteService) Logger(org.slf4j.Logger) Deactivate(org.osgi.service.component.annotations.Deactivate) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) BlockingQueue(java.util.concurrent.BlockingQueue) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) RouteListener(org.onosproject.routeservice.RouteListener) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) InternalRouteEvent(org.onosproject.routeservice.InternalRouteEvent) RouteInfo(org.onosproject.routeservice.RouteInfo) Optional(java.util.Optional) ClusterService(org.onosproject.cluster.ClusterService) RouteTableId(org.onosproject.routeservice.RouteTableId) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) Reference(org.osgi.service.component.annotations.Reference) IpPrefix(org.onlab.packet.IpPrefix) PredictableExecutor(org.onlab.util.PredictableExecutor) Activate(org.osgi.service.component.annotations.Activate)

Example 2 with ClusterService

use of org.onosproject.cluster.ClusterService 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 3 with ClusterService

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

the class ControlMetricsWebResource method cpuMetrics.

/**
 * Returns cpu metrics.
 *
 * @return cpu metrics
 * @onos.rsModel CpuMetrics
 */
@GET
@Path("cpu_metrics")
@Produces(MediaType.APPLICATION_JSON)
public Response cpuMetrics() {
    ObjectNode root = mapper().createObjectNode();
    ControlPlaneMonitorService monitorService = get(ControlPlaneMonitorService.class);
    ClusterService clusterService = get(ClusterService.class);
    NodeId localNodeId = clusterService.getLocalNode().id();
    metricsStats(monitorService, localNodeId, CPU_METRICS, root);
    return ok(root).build();
}
Also used : ClusterService(org.onosproject.cluster.ClusterService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ControlPlaneMonitorService(org.onosproject.cpman.ControlPlaneMonitorService) NodeId(org.onosproject.cluster.NodeId) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with ClusterService

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

the class ControlMetricsWebResource method diskMetrics.

/**
 * Returns disk metrics of all resources.
 *
 * @return disk metrics of all resources
 * @onos.rsModel DiskMetrics
 */
@GET
@Path("disk_metrics")
@Produces(MediaType.APPLICATION_JSON)
public Response diskMetrics() {
    ObjectNode root = mapper().createObjectNode();
    ControlPlaneMonitorService monitorService = get(ControlPlaneMonitorService.class);
    ClusterService clusterService = get(ClusterService.class);
    NodeId localNodeId = clusterService.getLocalNode().id();
    ArrayNode diskNodes = root.putArray("disks");
    monitorService.availableResourcesSync(localNodeId, DISK).forEach(name -> {
        ObjectNode diskNode = mapper().createObjectNode();
        ObjectNode valueNode = mapper().createObjectNode();
        metricsStats(monitorService, localNodeId, DISK_METRICS, name, valueNode);
        diskNode.put("name", name);
        diskNode.set("value", valueNode);
        diskNodes.add(diskNode);
    });
    return ok(root).build();
}
Also used : ClusterService(org.onosproject.cluster.ClusterService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ControlPlaneMonitorService(org.onosproject.cpman.ControlPlaneMonitorService) NodeId(org.onosproject.cluster.NodeId) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with ClusterService

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

the class ControlMetricsWebResource method networkMetrics.

/**
 * Returns network metrics of all resources.
 *
 * @return network metrics of all resources
 * @onos.rsModel NetworkMetrics
 */
@GET
@Path("network_metrics")
@Produces(MediaType.APPLICATION_JSON)
public Response networkMetrics() {
    ObjectNode root = mapper().createObjectNode();
    ControlPlaneMonitorService monitorService = get(ControlPlaneMonitorService.class);
    ClusterService clusterService = get(ClusterService.class);
    NodeId localNodeId = clusterService.getLocalNode().id();
    ArrayNode networkNodes = root.putArray("networks");
    monitorService.availableResourcesSync(localNodeId, NETWORK).forEach(name -> {
        ObjectNode networkNode = mapper().createObjectNode();
        ObjectNode valueNode = mapper().createObjectNode();
        metricsStats(monitorService, localNodeId, NETWORK_METRICS, name, valueNode);
        networkNode.put("name", name);
        networkNode.set("value", valueNode);
        networkNodes.add(networkNode);
    });
    return ok(root).build();
}
Also used : ClusterService(org.onosproject.cluster.ClusterService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ControlPlaneMonitorService(org.onosproject.cpman.ControlPlaneMonitorService) NodeId(org.onosproject.cluster.NodeId) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

ClusterService (org.onosproject.cluster.ClusterService)25 NodeId (org.onosproject.cluster.NodeId)17 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)8 ControllerNode (org.onosproject.cluster.ControllerNode)8 GET (javax.ws.rs.GET)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 ControlPlaneMonitorService (org.onosproject.cpman.ControlPlaneMonitorService)6 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)5 Set (java.util.Set)4 ExecutorService (java.util.concurrent.ExecutorService)3 Collectors (java.util.stream.Collectors)3 Command (org.apache.karaf.shell.api.action.Command)3 Option (org.apache.karaf.shell.api.action.Option)3 Before (org.junit.Before)3 IpAddress (org.onlab.packet.IpAddress)3 Sets (com.google.common.collect.Sets)2 Instant (java.time.Instant)2 Collection (java.util.Collection)2 Executors.newSingleThreadScheduledExecutor (java.util.concurrent.Executors.newSingleThreadScheduledExecutor)2