Search in sources :

Example 1 with HostService

use of org.onosproject.net.host.HostService in project onos by opennetworkinglab.

the class TsCheckLoop method doExecute.

@Override
protected void doExecute() {
    NetworkDiagnosticService service = getService(NetworkDiagnosticService.class);
    DeviceService ds = getService(DeviceService.class);
    HostService hs = getService(HostService.class);
    FlowRuleService frs = getService(FlowRuleService.class);
    LinkService ls = getService(LinkService.class);
    service.findAnomalies(NetworkDiagnostic.Type.LOOP).forEach(loop -> print(loop.toString()));
}
Also used : HostService(org.onosproject.net.host.HostService) DeviceService(org.onosproject.net.device.DeviceService) FlowRuleService(org.onosproject.net.flow.FlowRuleService) LinkService(org.onosproject.net.link.LinkService) NetworkDiagnosticService(org.onosproject.fnl.intf.NetworkDiagnosticService)

Example 2 with HostService

use of org.onosproject.net.host.HostService 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 3 with HostService

use of org.onosproject.net.host.HostService in project onos by opennetworkinglab.

the class Dhcp6HandlerUtil method processLQ6PacketFromServer.

/**
 * process the LQ reply packet from dhcp server.
 *
 * @param defaultServerInfoList default server list
 * @param indirectServerInfoList default indirect server list
 * @param serverInterface server interface
 * @param interfaceService interface service
 * @param hostService host service
 * @param context packet context
 * @param receivedPacket server ethernet packet
 * @param recevingInterfaces set of server side interfaces
 * @return a packet ready to be sent to relevant output interface
 */
public static InternalPacket processLQ6PacketFromServer(List<DhcpServerInfo> defaultServerInfoList, List<DhcpServerInfo> indirectServerInfoList, Interface serverInterface, InterfaceService interfaceService, HostService hostService, PacketContext context, Ethernet receivedPacket, Set<Interface> recevingInterfaces) {
    // get dhcp6 header.
    Ethernet etherReply = (Ethernet) receivedPacket.clone();
    IPv6 ipv6Packet = (IPv6) etherReply.getPayload();
    UDP udpPacket = (UDP) ipv6Packet.getPayload();
    DHCP6 lq6Reply = (DHCP6) udpPacket.getPayload();
    // TODO: refactor
    ConnectPoint receivedFrom = context.inPacket().receivedFrom();
    DeviceId receivedFromDevice = receivedFrom.deviceId();
    DhcpServerInfo serverInfo;
    Ip6Address dhcpServerIp = null;
    ConnectPoint dhcpServerConnectPoint = null;
    MacAddress dhcpConnectMac = null;
    VlanId dhcpConnectVlan = null;
    Ip6Address dhcpGatewayIp = null;
    // todo: refactor
    Ip6Address indirectDhcpServerIp = null;
    ConnectPoint indirectDhcpServerConnectPoint = null;
    MacAddress indirectDhcpConnectMac = null;
    VlanId indirectDhcpConnectVlan = null;
    Ip6Address indirectDhcpGatewayIp = null;
    Ip6Address indirectRelayAgentIpFromCfg = null;
    if (!defaultServerInfoList.isEmpty()) {
        serverInfo = defaultServerInfoList.get(0);
        dhcpConnectMac = serverInfo.getDhcpConnectMac().orElse(null);
        dhcpGatewayIp = serverInfo.getDhcpGatewayIp6().orElse(null);
        dhcpServerIp = serverInfo.getDhcpServerIp6().orElse(null);
        dhcpServerConnectPoint = serverInfo.getDhcpServerConnectPoint().orElse(null);
        dhcpConnectVlan = serverInfo.getDhcpConnectVlan().orElse(null);
    }
    if (!indirectServerInfoList.isEmpty()) {
        serverInfo = indirectServerInfoList.get(0);
        indirectDhcpConnectMac = serverInfo.getDhcpConnectMac().orElse(null);
        indirectDhcpGatewayIp = serverInfo.getDhcpGatewayIp6().orElse(null);
        indirectDhcpServerIp = serverInfo.getDhcpServerIp6().orElse(null);
        indirectDhcpServerConnectPoint = serverInfo.getDhcpServerConnectPoint().orElse(null);
        indirectDhcpConnectVlan = serverInfo.getDhcpConnectVlan().orElse(null);
        indirectRelayAgentIpFromCfg = serverInfo.getRelayAgentIp6(receivedFromDevice).orElse(null);
    }
    Boolean directConnFlag = directlyConnected(lq6Reply);
    ConnectPoint inPort = context.inPacket().receivedFrom();
    if ((directConnFlag || indirectDhcpServerIp == null) && !inPort.equals(dhcpServerConnectPoint)) {
        log.warn("Receiving port {} is not the same as server connect point {} for direct or indirect-null", inPort, dhcpServerConnectPoint);
        return null;
    }
    if (!directConnFlag && indirectDhcpServerIp != null && !inPort.equals(indirectDhcpServerConnectPoint)) {
        log.warn("Receiving port {} is not the same as server connect point {} for indirect", inPort, indirectDhcpServerConnectPoint);
        return null;
    }
    Ip6Address nextHopIP = Ip6Address.valueOf(ipv6Packet.getDestinationAddress());
    // use hosts store to find out the next hop mac and connection point
    Set<Host> hosts = hostService.getHostsByIp(nextHopIP);
    Host host;
    if (!hosts.isEmpty()) {
        host = hosts.iterator().next();
    } else {
        log.warn("Host {} is not in store", nextHopIP);
        return null;
    }
    HostLocation hl = host.location();
    // iterator().next());
    String clientConnectionPointStr = hl.toString();
    ConnectPoint clientConnectionPoint = ConnectPoint.deviceConnectPoint(clientConnectionPointStr);
    VlanId originalPacketVlanId = VlanId.vlanId(etherReply.getVlanID());
    Interface iface;
    iface = interfaceService.getInterfacesByPort(clientConnectionPoint).stream().filter(iface1 -> interfaceContainsVlan(iface1, originalPacketVlanId)).findFirst().orElse(null);
    etherReply.setSourceMACAddress(iface.mac());
    etherReply.setDestinationMACAddress(host.mac());
    // workaround for a bug where core sends src port as 547 (server)
    udpPacket.setDestinationPort(UDP.DHCP_V6_SERVER_PORT);
    udpPacket.setPayload(lq6Reply);
    udpPacket.resetChecksum();
    ipv6Packet.setPayload(udpPacket);
    etherReply.setPayload(ipv6Packet);
    return InternalPacket.internalPacket(etherReply, clientConnectionPoint);
}
Also used : UDP(org.onlab.packet.UDP) HostLocation(org.onosproject.net.HostLocation) Host(org.onosproject.net.Host) Interface(org.onosproject.net.intf.Interface) LoggerFactory(org.slf4j.LoggerFactory) InterfaceService(org.onosproject.net.intf.InterfaceService) HostService(org.onosproject.net.host.HostService) Dhcp6ClientIdOption(org.onlab.packet.dhcp.Dhcp6ClientIdOption) Dhcp6RelayOption(org.onlab.packet.dhcp.Dhcp6RelayOption) ConnectPoint(org.onosproject.net.ConnectPoint) ArrayList(java.util.ArrayList) Ethernet(org.onlab.packet.Ethernet) DhcpRelayCounters(org.onosproject.dhcprelay.store.DhcpRelayCounters) IpAddress(org.onlab.packet.IpAddress) BasePacket(org.onlab.packet.BasePacket) DhcpServerInfo(org.onosproject.dhcprelay.api.DhcpServerInfo) Ip6Address(org.onlab.packet.Ip6Address) Logger(org.slf4j.Logger) VlanId(org.onlab.packet.VlanId) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Dhcp6Option(org.onlab.packet.dhcp.Dhcp6Option) Set(java.util.Set) MsgType(org.onlab.packet.DHCP6.MsgType) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) UDP(org.onlab.packet.UDP) IPv6(org.onlab.packet.IPv6) DHCP6(org.onlab.packet.DHCP6) List(java.util.List) HexString(org.onlab.util.HexString) PacketContext(org.onosproject.net.packet.PacketContext) MacAddress(org.onlab.packet.MacAddress) DeviceId(org.onosproject.net.DeviceId) IPv6(org.onlab.packet.IPv6) DeviceId(org.onosproject.net.DeviceId) Host(org.onosproject.net.Host) HexString(org.onlab.util.HexString) MacAddress(org.onlab.packet.MacAddress) ConnectPoint(org.onosproject.net.ConnectPoint) Ip6Address(org.onlab.packet.Ip6Address) Ethernet(org.onlab.packet.Ethernet) HostLocation(org.onosproject.net.HostLocation) DHCP6(org.onlab.packet.DHCP6) DhcpServerInfo(org.onosproject.dhcprelay.api.DhcpServerInfo) VlanId(org.onlab.packet.VlanId) Interface(org.onosproject.net.intf.Interface)

Example 4 with HostService

use of org.onosproject.net.host.HostService in project onos by opennetworkinglab.

the class VirtualNetworkHostManagerTest method testGetHostByNullId.

/**
 * Tests querying for a host using a null host identifier.
 */
@Test(expected = NullPointerException.class)
public void testGetHostByNullId() {
    VirtualNetwork vnet = setupEmptyVnet();
    HostService hostService = manager.get(vnet.id(), HostService.class);
    hostService.getHost(null);
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) HostService(org.onosproject.net.host.HostService) Test(org.junit.Test)

Example 5 with HostService

use of org.onosproject.net.host.HostService in project onos by opennetworkinglab.

the class VirtualNetworkHostManagerTest method testGetHostsByNullVlan.

/**
 * Tests querying for hosts with null vlan.
 */
@Test(expected = NullPointerException.class)
public void testGetHostsByNullVlan() {
    VirtualNetwork vnet = setupEmptyVnet();
    HostService hostService = manager.get(vnet.id(), HostService.class);
    hostService.getHostsByVlan(null);
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) HostService(org.onosproject.net.host.HostService) Test(org.junit.Test)

Aggregations

HostService (org.onosproject.net.host.HostService)16 Test (org.junit.Test)8 VirtualNetwork (org.onosproject.incubator.net.virtual.VirtualNetwork)8 Host (org.onosproject.net.Host)8 StringsCompleter (org.apache.karaf.shell.support.completers.StringsCompleter)3 IpAddress (org.onlab.packet.IpAddress)3 Set (java.util.Set)2 VirtualHost (org.onosproject.incubator.net.virtual.VirtualHost)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 BlockingQueue (java.util.concurrent.BlockingQueue)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1