Java Code Examples for org.onosproject.net.Host#ipAddresses()

The following examples show how to use org.onosproject.net.Host#ipAddresses() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpenstackSwitchingHostProviderTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void addLocationToHost(HostId hostId, HostLocation location) {
    Host oldHost = hostMap.get(hostId);

    Set<HostLocation> newHostlocations = oldHost.locations();
    newHostlocations.add(location);

    Host newHost = new DefaultHost(oldHost.providerId(),
            oldHost.id(),
            oldHost.mac(),
            oldHost.vlan(),
            newHostlocations,
            oldHost.ipAddresses(),
            oldHost.innerVlan(),
            oldHost.tpid(),
            oldHost.configured(),
            oldHost.annotations());

    hostMap.put(hostId, newHost);
}
 
Example 2
Source File: HostsWebResource.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Creates and adds new host based on given data and returns its host ID.
 *
 * @param node JsonNode containing host information
 * @return host ID of new host created
 */
private HostId parseHost(JsonNode node) {
    Host host = codec(Host.class).decode((ObjectNode) node, HostsWebResource.this);

    HostId hostId = host.id();
    DefaultHostDescription desc = new DefaultHostDescription(
            host.mac(), host.vlan(), host.locations(), host.ipAddresses(), host.innerVlan(),
            host.tpid(), host.configured(), (SparseAnnotations) host.annotations());
    hostProviderService.hostDetected(hostId, desc, false);

    return hostId;
}
 
Example 3
Source File: Topo2Jsonifier.java    From onos with Apache License 2.0 5 votes vote down vote up
private void addIps(ObjectNode node, Host h) {
    Set<IpAddress> ips = h.ipAddresses();

    ArrayNode a = arrayNode();
    for (IpAddress ip : ips) {
        a.add(ip.toString());
    }

    node.set("ips", a);
}
 
Example 4
Source File: BasicHostOperator.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a description of the given host.
 *
 * @param host the host
 * @return a description of the host
 */
public static HostDescription descriptionOf(Host host) {
    checkNotNull(host, "Must supply a non-null Host");
    return new DefaultHostDescription(host.mac(), host.vlan(), host.locations(),
                                      host.ipAddresses(), host.configured(),
                                      (SparseAnnotations) host.annotations());
}
 
Example 5
Source File: HostCodec.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectNode encode(Host host, CodecContext context) {
    checkNotNull(host, NULL_OBJECT_MSG);

    final JsonCodec<HostLocation> locationCodec =
            context.codec(HostLocation.class);
    // keep fields in string for compatibility
    final ObjectNode result = context.mapper().createObjectNode()
            .put(HOST_ID, host.id().toString())
            .put(MAC, host.mac().toString())
            .put(VLAN, host.vlan().toString())
            .put(INNER_VLAN, host.innerVlan().toString())
            // use a 4-digit hex string in coding an ethernet type
            .put(OUTER_TPID, String.format("0x%04x", host.tpid().toShort()))
            .put(IS_CONFIGURED, host.configured())
            .put(IS_SUSPENDED, host.suspended());

    final ArrayNode jsonIpAddresses = result.putArray(IP_ADDRESSES);
    for (final IpAddress ipAddress : host.ipAddresses()) {
        jsonIpAddresses.add(ipAddress.toString());
    }
    result.set(IP_ADDRESSES, jsonIpAddresses);

    final ArrayNode jsonLocations = result.putArray(HOST_LOCATIONS);
    for (final HostLocation location : host.locations()) {
        jsonLocations.add(locationCodec.encode(location, context));
    }
    result.set(HOST_LOCATIONS, jsonLocations);

    if (host.auxLocations() != null) {
        final ArrayNode jsonAuxLocations = result.putArray(AUX_LOCATIONS);
        for (final HostLocation auxLocation : host.auxLocations()) {
            jsonAuxLocations.add(locationCodec.encode(auxLocation, context));
        }
        result.set(AUX_LOCATIONS, jsonAuxLocations);
    }

    return annotate(result, host, context);
}
 
Example 6
Source File: DefaultHostProbe.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs DefaultHostProbe with given retry.
 *
 * @param host host to be probed
 * @param connectPoint location to be verified
 * @param probeMac source MAC address of the probe
 * @param mode probe mode
 * @param retry number of retry
 */
DefaultHostProbe(Host host, ConnectPoint connectPoint, ProbeMode mode, MacAddress probeMac, int retry) {
    super(host.providerId(), host.id(), host.mac(), host.vlan(), host.locations(), host.ipAddresses(),
            host.configured());

    this.connectPoint = connectPoint;
    this.mode = mode;
    this.probeMac = probeMac;
    this.retry = retry;
}
 
Example 7
Source File: OpensteckTelemetryViewMessageHandler.java    From onos with Apache License 2.0 4 votes vote down vote up
private String ipForHost(Host host) {
    Set<IpAddress> ipAddresses = host.ipAddresses();
    Iterator<IpAddress> it = ipAddresses.iterator();
    return it.hasNext() ? it.next().toString() + "/32" : "unknown";
}
 
Example 8
Source File: OpenstackVtapViewMessageHandler.java    From onos with Apache License 2.0 4 votes vote down vote up
private String ipForHost(Host host) {
    Set<IpAddress> ipAddresses = host.ipAddresses();
    Iterator<IpAddress> it = ipAddresses.iterator();
    return it.hasNext() ? it.next().toString() + "/32" : "unknown";
}
 
Example 9
Source File: HostHandler.java    From onos with Apache License 2.0 4 votes vote down vote up
private void processHostRemoved(Host host) {
    MacAddress hostMac = host.mac();
    VlanId hostVlanId = host.vlan();
    Set<HostLocation> locations = effectiveLocations(host);
    Set<IpAddress> ips = host.ipAddresses();
    log.info("Host {}/{} is removed from {}", hostMac, hostVlanId, locations);

    locations.forEach(location -> {
        if (isDoubleTaggedHost(host)) {
            ips.forEach(ip ->
                processDoubleTaggedRoutingRule(location.deviceId(), location.port(), hostMac,
                                               host.innerVlan(), hostVlanId, host.tpid(), ip, true)
            );
        } else {
            processBridgingRule(location.deviceId(), location.port(), hostMac, hostVlanId, true);
            ips.forEach(ip ->
                processRoutingRule(location.deviceId(), location.port(), hostMac, hostVlanId, ip, true)
            );
        }

        // Also remove redirection flows on the pair device if exists.
        Optional<DeviceId> pairDeviceId = srManager.getPairDeviceId(location.deviceId());
        Optional<PortNumber> pairLocalPort = srManager.getPairLocalPort(location.deviceId());
        if (pairDeviceId.isPresent() && pairLocalPort.isPresent()) {
            // NOTE: Since the pairLocalPort is trunk port, use assigned vlan of original port
            //       when the host is untagged
            VlanId vlanId = vlanForPairPort(hostVlanId, location);
            if (vlanId == null) {
                return;
            }

            processBridgingRule(pairDeviceId.get(), pairLocalPort.get(), hostMac, vlanId, true);
            ips.forEach(ip ->
                    processRoutingRule(pairDeviceId.get(), pairLocalPort.get(), hostMac, vlanId,
                            ip, true));
        }

        // Delete prefix from sr-device-subnet when the next hop host is removed
        srManager.routeService.getRouteTables().forEach(tableId -> {
            srManager.routeService.getRoutes(tableId).forEach(routeInfo -> {
                if (routeInfo.allRoutes().stream().anyMatch(rr -> ips.contains(rr.nextHop()))) {
                    log.debug("HostRemoved. removeSubnet {}, {}", location, routeInfo.prefix());
                    srManager.deviceConfiguration.removeSubnet(location, routeInfo.prefix());
                }
            });
        });

    });
}
 
Example 10
Source File: HostHandler.java    From onos with Apache License 2.0 4 votes vote down vote up
private void processHostUpdatedEventInternal(HostEvent event) {
    Host host = event.subject();
    MacAddress hostMac = host.mac();
    VlanId hostVlanId = host.vlan();
    EthType hostTpid = host.tpid();
    Set<HostLocation> locations = effectiveLocations(host);
    Set<IpAddress> prevIps = event.prevSubject().ipAddresses();
    Set<IpAddress> newIps = host.ipAddresses();
    log.info("Host {}/{} is updated", hostMac, hostVlanId);

    locations.forEach(location -> {
        Sets.difference(prevIps, newIps).forEach(ip -> {
            if (isDoubleTaggedHost(host)) {
                processDoubleTaggedRoutingRule(location.deviceId(), location.port(), hostMac,
                                               host.innerVlan(), hostVlanId, hostTpid, ip, true);
            } else {
                processRoutingRule(location.deviceId(), location.port(), hostMac,
                                   hostVlanId, ip, true);
            }
        });
        Sets.difference(newIps, prevIps).forEach(ip -> {
            if (isDoubleTaggedHost(host)) {
                processDoubleTaggedRoutingRule(location.deviceId(), location.port(), hostMac,
                                               host.innerVlan(), hostVlanId, hostTpid, ip, false);
            } else {
                processRoutingRule(location.deviceId(), location.port(), hostMac,
                                   hostVlanId, ip, false);
            }
        });
    });

    // Use the pair link temporarily before the second location of a dual-homed host shows up.
    // This do not affect single-homed hosts since the flow will be blocked in
    // processBridgingRule or processRoutingRule due to VLAN or IP mismatch respectively
    locations.forEach(location ->
        srManager.getPairDeviceId(location.deviceId()).ifPresent(pairDeviceId -> {
            if (locations.stream().noneMatch(l -> l.deviceId().equals(pairDeviceId))) {
                Set<IpAddress> ipsToAdd = Sets.difference(newIps, prevIps);
                Set<IpAddress> ipsToRemove = Sets.difference(prevIps, newIps);

                srManager.getPairLocalPort(pairDeviceId).ifPresent(pairRemotePort -> {
                    // NOTE: Since the pairLocalPort is trunk port, use assigned vlan of original port
                    //       when the host is untagged
                    VlanId vlanId = vlanForPairPort(hostVlanId, location);
                    if (vlanId == null) {
                        return;
                    }

                    ipsToRemove.forEach(ip ->
                            processRoutingRule(pairDeviceId, pairRemotePort, hostMac, vlanId, ip, true)
                    );
                    ipsToAdd.forEach(ip ->
                            processRoutingRule(pairDeviceId, pairRemotePort, hostMac, vlanId, ip, false)
                    );

                    if (srManager.activeProbing) {
                        probe(host, location, pairDeviceId, pairRemotePort);
                    }
                });
            }
        })
    );
}
 
Example 11
Source File: MyTunnelApp.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Provisions a tunnel between the given source and destination host with
 * the given tunnel ID. The tunnel is established using a randomly picked
 * shortest path based on the given topology snapshot.
 *
 * @param tunId   tunnel ID
 * @param srcHost tunnel source host
 * @param dstHost tunnel destination host
 * @param topo    topology snapshot
 */
private void provisionTunnel(int tunId, Host srcHost, Host dstHost, Topology topo) {

    // Get all shortest paths between switches connected to source and
    // destination hosts.
    DeviceId srcSwitch = srcHost.location().deviceId();
    DeviceId dstSwitch = dstHost.location().deviceId();

    List<Link> pathLinks;
    if (srcSwitch.equals(dstSwitch)) {
        // Source and dest hosts are connected to the same switch.
        pathLinks = Collections.emptyList();
    } else {
        // Compute shortest path.
        Set<Path> allPaths = topologyService.getPaths(topo, srcSwitch, dstSwitch);
        if (allPaths.size() == 0) {
            log.warn("No paths between {} and {}", srcHost.id(), dstHost.id());
            return;
        }
        // If many shortest paths are available, pick a random one.
        pathLinks = pickRandomPath(allPaths).links();
    }

    // Tunnel ingress rules.
    for (IpAddress dstIpAddr : dstHost.ipAddresses()) {
        // In ONOS discovered hosts can have multiple IP addresses.
        // Insert tunnel ingress rule for each IP address.
        // Next switches will forward based only on tunnel ID.
        insertTunnelIngressRule(srcSwitch, dstIpAddr, tunId);
    }

    // Insert tunnel transit rules on all switches in the path, excluded the
    // last one.
    for (Link link : pathLinks) {
        DeviceId sw = link.src().deviceId();
        PortNumber port = link.src().port();
        insertTunnelForwardRule(sw, port, tunId, false);
    }

    // Tunnel egress rule.
    PortNumber egressSwitchPort = dstHost.location().port();
    insertTunnelForwardRule(dstSwitch, egressSwitchPort, tunId, true);

    log.info("** Completed provisioning of tunnel {} (srcHost={} dstHost={})",
             tunId, srcHost.id(), dstHost.id());
}
 
Example 12
Source File: TopologySimulator.java    From onos with Apache License 2.0 2 votes vote down vote up
/**
 * Produces a host description from the given host.
 *
 * @param host host to copy
 * @return host description
 */
static DefaultHostDescription description(Host host) {
    return new DefaultHostDescription(host.mac(), host.vlan(), host.location(),
                                      host.ipAddresses());
}