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

The following examples show how to use org.onosproject.net.Host#vlan() . 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: StatsFlowRuleManager.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Gets VLAN ID with respect to IP Address.
 *
 * @param ipAddress IP Address of host
 * @return VLAN ID
 */
private VlanId getVlanId(IpAddress ipAddress) {
    if (!hostService.getHostsByIp(ipAddress).isEmpty()) {
        Host host = hostService.getHostsByIp(ipAddress).stream().findAny().get();
        return host.vlan();
    }
    return VlanId.vlanId();
}
 
Example 4
Source File: BgpSpeakerNeighbourHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void handleMessage(NeighbourMessageContext context, HostService hostService) {
    switch (context.type()) {
    case REQUEST:
        // Reply to requests that target our configured interface IP
        // address on this port. Drop all other requests.
        interfaceService.getInterfacesByPort(context.inPort())
                .stream()
                .filter(intf -> intf.ipAddressesList()
                        .stream()
                        .anyMatch(ia -> ia.ipAddress().equals(context.target()) &&
                                ia.subnetAddress().contains(context.sender())))
                .forEach(intf -> context.reply(intf.mac()));

        break;
    case REPLY:
        // Proxy replies over to our internal BGP speaker if the host
        // is known to us
        Set<Host> hosts = hostService.getHostsByMac(context.dstMac());

        if (hosts.isEmpty()) {
            context.drop();
        } else {
            Host h = hosts.stream().findFirst().get();
            VlanId bgpSpeakerVlanId = h.vlan();

            if (!bgpSpeakerVlanId.equals(VlanId.NONE)) {
                context.packet().setVlanID(bgpSpeakerVlanId.toShort());
            } else {
                context.packet().setVlanID(Ethernet.VLAN_UNTAGGED);
            }
            context.forward(h.location());
        }
        break;
    default:
        break;
    }
}
 
Example 5
Source File: SimpleFabricForwarding.java    From onos with Apache License 2.0 5 votes vote down vote up
protected FilteredConnectPoint buildFilteredConnectedPoint(Host host) {
    Objects.requireNonNull(host);
    TrafficSelector.Builder trafficSelector = DefaultTrafficSelector.builder();

    if (host.vlan() != null && !host.vlan().equals(VlanId.NONE)) {
        trafficSelector.matchVlanId(host.vlan());
    }
    return new FilteredConnectPoint(host.location(), trafficSelector.build());
}
 
Example 6
Source File: VplsIntentUtility.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Builds filtered connected point by a given host.
 *
 * @param host the host
 * @return the filtered connected point of the given host
 */
static FilteredConnectPoint buildFilteredConnectedPoint(Host host) {
    requireNonNull(host);
    TrafficSelector.Builder trafficSelector = DefaultTrafficSelector.builder();

    if (host.vlan() != null && !host.vlan().equals(VlanId.NONE)) {
        trafficSelector.matchVlanId(host.vlan());
    }
    return new FilteredConnectPoint(host.location(), trafficSelector.build());
}
 
Example 7
Source File: VplsNeighbourHandlerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Generates broadcast request message context by given source host.
 *
 * @param host the source host
 * @return the request message context
 */
private TestMessageContext makeBroadcastRequestContext(Host host) {
    return new TestMessageContext(host.location(),
                                  host.mac(),
                                  MacAddress.BROADCAST,
                                  host.vlan(),
                                  NeighbourMessageType.REQUEST);
}
 
Example 8
Source File: VplsNeighbourHandlerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Generates reply message context by given source and destination host.
 *
 * @param src the source host
 * @param dst the destination host
 * @return the reply message context
 */
private TestMessageContext makeReplyContext(Host src, Host dst) {
    return new TestMessageContext(src.location(),
                                  src.mac(),
                                  dst.mac(),
                                  src.vlan(),
                                  NeighbourMessageType.REPLY);
}
 
Example 9
Source File: HostHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Send a probe on all locations with the same VLAN on pair device, excluding pair port.
 *
 * @param host host to probe
 * @param location newly discovered host location
 * @param pairDeviceId pair device id
 * @param pairRemotePort pair remote port
 */
// TODO Current implementation does not handle dual-homed hosts with auxiliary locations.
private void probe(Host host, ConnectPoint location, DeviceId pairDeviceId, PortNumber pairRemotePort) {
    //Check if the host still exists in the host store
    if (hostService.getHost(host.id()) == null) {
        log.debug("Host entry for host {} no more present. Aborting hostprobe discover for this host", host.id());
        return;
    }

    VlanId vlanToProbe = host.vlan().equals(VlanId.NONE) ?
            srManager.getInternalVlanId(location) : host.vlan();
    if (srManager.symmetricProbing) {
        srManager.interfaceService.getInterfaces().stream()
                .filter(i -> i.vlanTagged().contains(vlanToProbe) ||
                        i.vlanUntagged().equals(vlanToProbe) ||
                        i.vlanNative().equals(vlanToProbe))
                .filter(i -> i.connectPoint().deviceId().equals(pairDeviceId))
                .filter(i -> i.connectPoint().port().equals(location.port()))
                .forEach(i -> {
                    log.debug("Probing host {} on pair device {}", host.id(), i.connectPoint());
                    srManager.probingService.probeHost(host, i.connectPoint(), ProbeMode.DISCOVER);
                });
    } else {
        srManager.interfaceService.getInterfaces().stream()
                .filter(i -> i.vlanTagged().contains(vlanToProbe) ||
                        i.vlanUntagged().equals(vlanToProbe) ||
                        i.vlanNative().equals(vlanToProbe))
                .filter(i -> i.connectPoint().deviceId().equals(pairDeviceId))
                .filter(i -> !i.connectPoint().port().equals(pairRemotePort))
                .forEach(i -> {
                    log.debug("Probing host {} on pair device {}", host.id(), i.connectPoint());
                    srManager.probingService.probeHost(host, i.connectPoint(), ProbeMode.DISCOVER);
                });
    }
}
 
Example 10
Source File: HostHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
private void processIntfVlanUpdatedEventInternal(Host host, DeviceId deviceId, PortNumber portNum,
                                                 VlanId vlanId, boolean popVlan, boolean install) {
    MacAddress mac = host.mac();
    VlanId hostVlanId = host.vlan();

    if (!install) {
        // Do not check the host validity. Just remove all rules corresponding to the vlan id
        // Revoke forwarding objective for bridging to the host
        srManager.defaultRoutingHandler.updateBridging(deviceId, portNum, mac, vlanId, popVlan, false);

        // Revoke forwarding objective and corresponding simple Next objective
        // for each Host and IP address connected to given port
        host.ipAddresses().forEach(ipAddress ->
            srManager.routingRulePopulator.updateFwdObj(deviceId, portNum, ipAddress.toIpPrefix(),
                                                        mac, vlanId, popVlan, false)
        );
    } else {
        // Check whether the host vlan is valid for new interface configuration
        if ((!popVlan && hostVlanId.equals(vlanId)) ||
                (popVlan && hostVlanId.equals(VlanId.NONE))) {
            srManager.defaultRoutingHandler.updateBridging(deviceId, portNum, mac, vlanId, popVlan, true);
            // Update Forwarding objective and corresponding simple Next objective
            // for each Host and IP address connected to given port
            host.ipAddresses().forEach(ipAddress ->
                srManager.routingRulePopulator.updateFwdObj(deviceId, portNum, ipAddress.toIpPrefix(),
                                                            mac, vlanId, popVlan, true)
            );
        }
    }
}
 
Example 11
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 12
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 13
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 14
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 15
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());
}