Search in sources :

Example 26 with HostId

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

the class McastShowHostCommand method prepareResult.

private void prepareResult(MulticastRouteService mcastService, McastRoute route) {
    if (outputJson()) {
        // McastHostRouteCodec is used to encode McastRoute
        ObjectNode routeNode = jsonForEntity(route, McastRoute.class);
        routesNode.add(routeNode);
    } else {
        Map<HostId, Set<ConnectPoint>> sinks = mcastService.routeData(route).sinks();
        Map<HostId, Set<ConnectPoint>> sources = mcastService.routeData(route).sources();
        String srcIp = "*";
        if (route.source().isPresent()) {
            srcIp = route.source().get().toString();
        }
        routesBuilder.append(String.format(FORMAT_MAPPING, route.type(), route.group(), srcIp, sources, sinks));
    }
}
Also used : Set(java.util.Set) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HostId(org.onosproject.net.HostId)

Example 27 with HostId

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

the class McastSinkDeleteCommand method doExecute.

@Override
protected void doExecute() {
    MulticastRouteService mcastRouteManager = get(MulticastRouteService.class);
    // Clear all routes
    if ("*".equals(sAddr) && "*".equals(gAddr)) {
        mcastRouteManager.getRoutes().forEach(mcastRouteManager::remove);
        return;
    }
    // Removing/updating a specific entry
    IpAddress sAddrIp = null;
    // If the source Ip is * we want ASM so we leave it as null and the route will have it as an optional.empty()
    if (!sAddr.equals("*")) {
        sAddrIp = IpAddress.valueOf(sAddr);
    }
    McastRoute mRoute = new McastRoute(sAddrIp, IpAddress.valueOf(gAddr), McastRoute.Type.STATIC);
    // If the user provides only sAddr and gAddr, we have to remove the route
    if (host == null || host.isEmpty()) {
        mcastRouteManager.remove(mRoute);
        printMcastRoute(D_FORMAT_MAPPING, mRoute);
        return;
    }
    // Otherwise we need to remove a specific sink
    HostId hostId = HostId.hostId(host);
    if (!mcastRouteManager.getRoutes().contains(mRoute)) {
        print("Route is not present, store it first");
        return;
    }
    // Remove the entire host id
    mcastRouteManager.removeSink(mRoute, hostId);
    // We have done
    printMcastRoute(U_FORMAT_MAPPING, mRoute);
}
Also used : MulticastRouteService(org.onosproject.mcast.api.MulticastRouteService) IpAddress(org.onlab.packet.IpAddress) McastRoute(org.onosproject.mcast.api.McastRoute) HostId(org.onosproject.net.HostId)

Example 28 with HostId

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

the class HostManagerTest method validateHosts.

private void validateHosts(String msg, Iterable<Host> hosts, HostId... ids) {
    Set<HostId> hids = Sets.newHashSet(ids);
    for (Host h : hosts) {
        assertTrue(msg, hids.remove(h.id()));
    }
    assertTrue("expected hosts not fetched from store", hids.isEmpty());
}
Also used : Host(org.onosproject.net.Host) HostId(org.onosproject.net.HostId)

Example 29 with HostId

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

the class LayoutAlgorithm method placeHostBlock.

/**
 * Places the specified collection of hosts (all presumably connected to
 * the same network device) in a block.
 *
 * @param hosts       hosts to place
 * @param gridX       grid X of the top of the block
 * @param gridY       grid Y of the center of the block
 * @param hostsPerRow number of hosts in a 'row'
 * @param rowGap      gap width between rows
 * @param colGap      gap width between columns
 */
protected void placeHostBlock(Collection<HostId> hosts, double gridX, double gridY, int hostsPerRow, double rowGap, double colGap) {
    double yStep = rowGap / hostsPerRow;
    double y = gridY;
    double x = gridX - (colGap * (hostsPerRow - 1)) / 2;
    int i = 1;
    for (HostId id : hosts) {
        place(id, x, y);
        if ((i % hostsPerRow) == 0) {
            x = gridX - (colGap * (hostsPerRow - 1)) / 2;
        } else {
            x += colGap;
            y += yStep;
        }
        i++;
    }
}
Also used : HostId(org.onosproject.net.HostId)

Example 30 with HostId

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

the class OpenstackSwitchingHostProvider method processPortAdded.

/**
 * Processes port addition event.
 * Once a port addition event is detected, it tries to create a host instance
 * with openstack augmented host information such as networkId, portId,
 * createTime, segmentId and notifies to host provider.
 *
 * @param port port object used in ONOS
 */
void processPortAdded(Port port) {
    // TODO check the node state is COMPLETE
    org.openstack4j.model.network.Port osPort = osNetworkService.port(port);
    if (osPort == null) {
        log.warn(ERR_ADD_HOST + "OpenStack port for {} not found", port);
        return;
    }
    Network osNet = osNetworkService.network(osPort.getNetworkId());
    if (osNet == null) {
        log.warn(ERR_ADD_HOST + "OpenStack network {} not found", osPort.getNetworkId());
        return;
    }
    if (osPort.getFixedIps().isEmpty()) {
        log.warn(ERR_ADD_HOST + "no fixed IP for port {}", osPort.getId());
        return;
    }
    MacAddress mac = MacAddress.valueOf(osPort.getMacAddress());
    HostId hostId = HostId.hostId(mac);
    /* typically one openstack port should only be bound to one fix IP address;
           however, openstack4j binds multiple fixed IPs to one port, this might
           be a defect of openstack4j implementation */
    // TODO: we need to find a way to bind multiple ports from multiple
    // openstack networks into one host sooner or later
    Set<IpAddress> fixedIps = osPort.getFixedIps().stream().map(ip -> IpAddress.valueOf(ip.getIpAddress())).collect(Collectors.toSet());
    // 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();
    // 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, osPort.getNetworkId()).set(ANNOTATION_PORT_ID, osPort.getId()).set(ANNOTATION_CREATE_TIME, String.valueOf(createTime));
    // FLAT typed network does not require segment ID
    Type netType = osNetworkService.networkType(osNet.getId());
    if (netType != FLAT) {
        annotations.set(ANNOTATION_SEGMENT_ID, osNet.getProviderSegID());
    }
    // build host description object
    HostDescription hostDesc = new DefaultHostDescription(mac, VlanId.NONE, new HostLocation(connectPoint, createTime), fixedIps, 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) CoreService(org.onosproject.core.CoreService) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) Constants(org.onosproject.openstacknetworking.api.Constants) OpenstackNetworkListener(org.onosproject.openstacknetworking.api.OpenstackNetworkListener) OpenstackNetworkingUtil.vnicType(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.vnicType) ConnectPoint(org.onosproject.net.ConnectPoint) HostProviderService(org.onosproject.net.host.HostProviderService) OpenstackNodeListener(org.onosproject.openstacknode.api.OpenstackNodeListener) TUNNEL_TYPE(org.onosproject.openstacknetworking.api.Constants.TUNNEL_TYPE) Port(org.onosproject.net.Port) Type(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type) OpenstackNetworkEvent(org.onosproject.openstacknetworking.api.OpenstackNetworkEvent) MastershipService(org.onosproject.mastership.MastershipService) OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) Constants.portNamePrefixMap(org.onosproject.openstacknetworking.api.Constants.portNamePrefixMap) 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) OPENSTACK_NETWORKING_APP_ID(org.onosproject.openstacknetworking.api.Constants.OPENSTACK_NETWORKING_APP_ID) FLAT(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.FLAT) DeviceEvent(org.onosproject.net.device.DeviceEvent) Optional(java.util.Optional) HostDescription(org.onosproject.net.host.HostDescription) ANNOTATION_NETWORK_ID(org.onosproject.openstacknetworking.api.Constants.ANNOTATION_NETWORK_ID) HostProviderRegistry(org.onosproject.net.host.HostProviderRegistry) Tools(org.onlab.util.Tools) Host(org.onosproject.net.Host) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) Network(org.openstack4j.model.network.Network) PORT_NAME(org.onosproject.net.AnnotationKeys.PORT_NAME) PORT_NAME_PREFIX_VM(org.onosproject.openstacknetworking.api.Constants.PORT_NAME_PREFIX_VM) HostService(org.onosproject.net.host.HostService) CONTROLLER(org.onosproject.openstacknode.api.OpenstackNode.NodeType.CONTROLLER) Strings(com.google.common.base.Strings) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) PORT_NAME_VHOST_USER_PREFIX_VM(org.onosproject.openstacknetworking.api.Constants.PORT_NAME_VHOST_USER_PREFIX_VM) DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) Component(org.osgi.service.component.annotations.Component) ANNOTATION_SEGMENT_ID(org.onosproject.openstacknetworking.api.Constants.ANNOTATION_SEGMENT_ID) Activate(org.osgi.service.component.annotations.Activate) HostId(org.onosproject.net.HostId) ExecutorService(java.util.concurrent.ExecutorService) IpAddress(org.onlab.packet.IpAddress) AbstractProvider(org.onosproject.net.provider.AbstractProvider) ANNOTATION_PORT_ID(org.onosproject.openstacknetworking.api.Constants.ANNOTATION_PORT_ID) DeviceListener(org.onosproject.net.device.DeviceListener) Logger(org.slf4j.Logger) HostProvider(org.onosproject.net.host.HostProvider) VlanId(org.onlab.packet.VlanId) ANNOTATION_CREATE_TIME(org.onosproject.openstacknetworking.api.Constants.ANNOTATION_CREATE_TIME) ProviderId(org.onosproject.net.provider.ProviderId) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) OpenstackNodeEvent(org.onosproject.openstacknode.api.OpenstackNodeEvent) MacAddress(org.onlab.packet.MacAddress) 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) OpenstackNetworkingUtil.vnicType(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.vnicType) Type(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type) Network(org.openstack4j.model.network.Network) HostLocation(org.onosproject.net.HostLocation) IpAddress(org.onlab.packet.IpAddress)

Aggregations

HostId (org.onosproject.net.HostId)86 IpAddress (org.onlab.packet.IpAddress)27 DeviceId (org.onosproject.net.DeviceId)24 VlanId (org.onlab.packet.VlanId)23 HostLocation (org.onosproject.net.HostLocation)23 MacAddress (org.onlab.packet.MacAddress)21 Test (org.junit.Test)18 ConnectPoint (org.onosproject.net.ConnectPoint)17 Host (org.onosproject.net.Host)17 HostDescription (org.onosproject.net.host.HostDescription)16 DefaultHostDescription (org.onosproject.net.host.DefaultHostDescription)14 Set (java.util.Set)13 DhcpRecord (org.onosproject.dhcprelay.store.DhcpRecord)12 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)11 HashSet (java.util.HashSet)11 Logger (org.slf4j.Logger)11 ImmutableSet (com.google.common.collect.ImmutableSet)10 Device (org.onosproject.net.Device)10 Path (org.onosproject.net.Path)10 LoggerFactory (org.slf4j.LoggerFactory)10