Search in sources :

Example 1 with Host

use of org.onosproject.net.Host in project onos by opennetworkinglab.

the class K8sSwitchingHostProvider method processPortAdded.

/**
 * Processes port addition event.
 *
 * @param port port object used in ONOS
 */
private void processPortAdded(Port port) {
    K8sPort k8sPort = portToK8sPortByName(port);
    if (k8sPort == null) {
        k8sPort = portToK8sPortByMac(port);
        if (k8sPort == null) {
            log.warn(ERR_ADD_HOST + "Kubernetes port for {} not found", port);
            return;
        }
    }
    K8sNetwork k8sNet = k8sNetworkService.network(k8sPort.networkId());
    if (k8sNet == null) {
        log.warn(ERR_ADD_HOST + "Kubernetes network {} not found", k8sPort.networkId());
        return;
    }
    MacAddress mac = k8sPort.macAddress();
    HostId hostId = HostId.hostId(mac);
    // connect point is the combination of switch ID with port number where
    // the host is attached to
    ConnectPoint connectPoint = new ConnectPoint(port.element().id(), port.number());
    long createTime = System.currentTimeMillis();
    // update k8s port number by referring to ONOS port number
    k8sNetworkService.updatePort(k8sPort.updatePortNumber(port.number()).updateState(K8sPort.State.ACTIVE));
    // we check whether the host already attached to same locations
    Host host = hostService.getHost(hostId);
    // build host annotations to include a set of meta info from neutron
    DefaultAnnotations.Builder annotations = DefaultAnnotations.builder().set(ANNOTATION_NETWORK_ID, k8sPort.networkId()).set(ANNOTATION_PORT_ID, k8sPort.portId()).set(ANNOTATION_CREATE_TIME, String.valueOf(createTime)).set(ANNOTATION_SEGMENT_ID, k8sNet.segmentId());
    HostDescription hostDesc = new DefaultHostDescription(mac, VlanId.NONE, new HostLocation(connectPoint, createTime), ImmutableSet.of(k8sPort.ipAddress()), annotations.build());
    if (host != null) {
        Set<HostLocation> locations = host.locations().stream().filter(l -> l.deviceId().equals(connectPoint.deviceId())).filter(l -> l.port().equals(connectPoint.port())).collect(Collectors.toSet());
        // therefore, we simply add this into the location list
        if (locations.isEmpty()) {
            hostProviderService.addLocationToHost(hostId, new HostLocation(connectPoint, createTime));
        }
        // the hostDetected method invocation in turn triggers host Update event
        if (locations.size() == 1) {
            hostProviderService.hostDetected(hostId, hostDesc, false);
        }
    } else {
        hostProviderService.hostDetected(hostId, hostDesc, false);
    }
}
Also used : HostLocation(org.onosproject.net.HostLocation) K8sNetworkingUtil.existingContainerPortByName(org.onosproject.k8snetworking.util.K8sNetworkingUtil.existingContainerPortByName) CoreService(org.onosproject.core.CoreService) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) K8sNodeListener(org.onosproject.k8snode.api.K8sNodeListener) K8sNetworkListener(org.onosproject.k8snetworking.api.K8sNetworkListener) ConnectPoint(org.onosproject.net.ConnectPoint) HostProviderService(org.onosproject.net.host.HostProviderService) Port(org.onosproject.net.Port) PORT_MAC(org.onosproject.net.AnnotationKeys.PORT_MAC) K8sNetworkingUtil.isContainer(org.onosproject.k8snetworking.util.K8sNetworkingUtil.isContainer) MastershipService(org.onosproject.mastership.MastershipService) ANNOTATION_CREATE_TIME(org.onosproject.k8snetworking.api.Constants.ANNOTATION_CREATE_TIME) ImmutableSet(com.google.common.collect.ImmutableSet) Device(org.onosproject.net.Device) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) GENEVE(org.onosproject.k8snetworking.api.Constants.GENEVE) DeviceEvent(org.onosproject.net.device.DeviceEvent) K8sNetworkAdminService(org.onosproject.k8snetworking.api.K8sNetworkAdminService) DeviceId(org.onosproject.net.DeviceId) HostDescription(org.onosproject.net.host.HostDescription) INIT(org.onosproject.k8snode.api.K8sNodeState.INIT) HostProviderRegistry(org.onosproject.net.host.HostProviderRegistry) Tools(org.onlab.util.Tools) Host(org.onosproject.net.Host) PORT_NAME(org.onosproject.net.AnnotationKeys.PORT_NAME) GRE(org.onosproject.k8snetworking.api.Constants.GRE) HostService(org.onosproject.net.host.HostService) Strings(com.google.common.base.Strings) DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) Component(org.osgi.service.component.annotations.Component) ANNOTATION_PORT_ID(org.onosproject.k8snetworking.api.Constants.ANNOTATION_PORT_ID) ANNOTATION_NETWORK_ID(org.onosproject.k8snetworking.api.Constants.ANNOTATION_NETWORK_ID) K8sNetworkEvent(org.onosproject.k8snetworking.api.K8sNetworkEvent) K8sPort(org.onosproject.k8snetworking.api.K8sPort) K8sNodeEvent(org.onosproject.k8snode.api.K8sNodeEvent) Activate(org.osgi.service.component.annotations.Activate) K8sNode(org.onosproject.k8snode.api.K8sNode) HostId(org.onosproject.net.HostId) ExecutorService(java.util.concurrent.ExecutorService) K8S_NETWORKING_APP_ID(org.onosproject.k8snetworking.api.Constants.K8S_NETWORKING_APP_ID) AbstractProvider(org.onosproject.net.provider.AbstractProvider) DeviceListener(org.onosproject.net.device.DeviceListener) Logger(org.slf4j.Logger) HostProvider(org.onosproject.net.host.HostProvider) VXLAN(org.onosproject.k8snetworking.api.Constants.VXLAN) VlanId(org.onlab.packet.VlanId) K8sHostService(org.onosproject.k8snode.api.K8sHostService) ProviderId(org.onosproject.net.provider.ProviderId) ANNOTATION_SEGMENT_ID(org.onosproject.k8snetworking.api.Constants.ANNOTATION_SEGMENT_ID) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) K8sNetworkingUtil.existingContainerPortByMac(org.onosproject.k8snetworking.util.K8sNetworkingUtil.existingContainerPortByMac) K8sNetwork(org.onosproject.k8snetworking.api.K8sNetwork) K8sNetworkingUtil.allK8sDevices(org.onosproject.k8snetworking.util.K8sNetworkingUtil.allK8sDevices) MacAddress(org.onlab.packet.MacAddress) K8sNodeService(org.onosproject.k8snode.api.K8sNodeService) Reference(org.osgi.service.component.annotations.Reference) DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Host(org.onosproject.net.Host) MacAddress(org.onlab.packet.MacAddress) HostId(org.onosproject.net.HostId) ConnectPoint(org.onosproject.net.ConnectPoint) HostDescription(org.onosproject.net.host.HostDescription) DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) K8sNetwork(org.onosproject.k8snetworking.api.K8sNetwork) HostLocation(org.onosproject.net.HostLocation) K8sPort(org.onosproject.k8snetworking.api.K8sPort)

Example 2 with Host

use of org.onosproject.net.Host in project onos by opennetworkinglab.

the class MulticastRouteManager method addSink.

@Override
public void addSink(McastRoute route, HostId hostId) {
    if (checkRoute(route)) {
        Set<ConnectPoint> sinks = new HashSet<>();
        Host host = hostService.getHost(hostId);
        if (host != null) {
            sinks.addAll(host.locations());
        }
        store.addSink(route, hostId, sinks);
    }
}
Also used : Host(org.onosproject.net.Host) ConnectPoint(org.onosproject.net.ConnectPoint) HashSet(java.util.HashSet)

Example 3 with Host

use of org.onosproject.net.Host in project onos by opennetworkinglab.

the class MulticastRouteManager method addSource.

@Override
public void addSource(McastRoute route, HostId source) {
    checkNotNull(route, "Route cannot be null");
    checkNotNull(source, "Source cannot be null");
    if (checkRoute(route)) {
        Set<ConnectPoint> sources = new HashSet<>();
        Host host = hostService.getHost(source);
        if (host != null) {
            sources.addAll(host.locations());
        }
        store.storeSource(route, source, sources);
    }
}
Also used : Host(org.onosproject.net.Host) ConnectPoint(org.onosproject.net.ConnectPoint) HashSet(java.util.HashSet)

Example 4 with Host

use of org.onosproject.net.Host 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 5 with Host

use of org.onosproject.net.Host in project onos by opennetworkinglab.

the class RouteManagerTest method testAsyncRouteAdd.

/**
 * Tests adding a route entry where the HostService does not immediately
 * know the MAC address of the next hop, but this is learnt later.
 */
@Test
public void testAsyncRouteAdd() {
    Route route = new Route(Route.Source.STATIC, V4_PREFIX1, V4_NEXT_HOP1);
    // 2nd route for the same nexthop
    Route route2 = new Route(Route.Source.STATIC, V4_PREFIX2, V4_NEXT_HOP2);
    // 3rd route with no valid nexthop
    Route route3 = new Route(Route.Source.STATIC, V6_PREFIX1, V6_NEXT_HOP1);
    // Host service will reply with no hosts when asked
    reset(hostService);
    expect(hostService.getHostsByIp(anyObject(IpAddress.class))).andReturn(Collections.emptySet()).anyTimes();
    hostService.startMonitoringIp(V4_NEXT_HOP1);
    hostService.startMonitoringIp(V4_NEXT_HOP2);
    hostService.startMonitoringIp(V6_NEXT_HOP1);
    expectLastCall().anyTimes();
    replay(hostService);
    // Initially when we add the route, no route event will be sent because
    // the host is not known
    replay(routeListener);
    routeManager.update(Lists.newArrayList(route, route2, route3));
    verify(routeListener);
    // Now when we send the event, we expect the FIB update to be sent
    reset(routeListener);
    ResolvedRoute resolvedRoute = new ResolvedRoute(route, MAC1);
    routeListener.event(event(RouteEvent.Type.ROUTE_ADDED, resolvedRoute, null, Sets.newHashSet(resolvedRoute), null));
    ResolvedRoute resolvedRoute2 = new ResolvedRoute(route2, MAC1);
    routeListener.event(event(RouteEvent.Type.ROUTE_ADDED, resolvedRoute2, null, Sets.newHashSet(resolvedRoute2), null));
    replay(routeListener);
    Host host = createHost(MAC1, Lists.newArrayList(V4_NEXT_HOP1, V4_NEXT_HOP2));
    // Set up the host service with a host
    reset(hostService);
    expect(hostService.getHostsByIp(V4_NEXT_HOP1)).andReturn(Collections.singleton(host)).anyTimes();
    hostService.startMonitoringIp(V4_NEXT_HOP1);
    expect(hostService.getHostsByIp(V4_NEXT_HOP2)).andReturn(Collections.singleton(host)).anyTimes();
    hostService.startMonitoringIp(V4_NEXT_HOP2);
    expectLastCall().anyTimes();
    replay(hostService);
    // Send in the host event
    hostListener.event(new HostEvent(HostEvent.Type.HOST_ADDED, host));
    verify(routeListener);
}
Also used : HostEvent(org.onosproject.net.host.HostEvent) Host(org.onosproject.net.Host) DefaultHost(org.onosproject.net.DefaultHost) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) Route(org.onosproject.routeservice.Route) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) Test(org.junit.Test)

Aggregations

Host (org.onosproject.net.Host)98 IpAddress (org.onlab.packet.IpAddress)40 MacAddress (org.onlab.packet.MacAddress)40 HostService (org.onosproject.net.host.HostService)34 ConnectPoint (org.onosproject.net.ConnectPoint)33 Set (java.util.Set)29 VlanId (org.onlab.packet.VlanId)29 HostLocation (org.onosproject.net.HostLocation)28 HostId (org.onosproject.net.HostId)27 Logger (org.slf4j.Logger)27 Interface (org.onosproject.net.intf.Interface)25 LoggerFactory (org.slf4j.LoggerFactory)25 ImmutableSet (com.google.common.collect.ImmutableSet)23 DeviceId (org.onosproject.net.DeviceId)23 TrafficSelector (org.onosproject.net.flow.TrafficSelector)22 DefaultHostDescription (org.onosproject.net.host.DefaultHostDescription)22 HostDescription (org.onosproject.net.host.HostDescription)22 List (java.util.List)21 Test (org.junit.Test)21 DefaultHost (org.onosproject.net.DefaultHost)21