Search in sources :

Example 6 with ConnectPoint

use of org.onosproject.net.ConnectPoint in project trellis-control by opennetworkinglab.

the class DeviceConfiguration method getPortSubnets.

/**
 * Returns the subnet configuration of given device and port.
 *
 * @param deviceId Device ID
 * @param port Port number
 * @return The subnets configured on given port or empty set if
 *         the port is unconfigured or suppressed.
 */
public Set<IpPrefix> getPortSubnets(DeviceId deviceId, PortNumber port) {
    ConnectPoint connectPoint = new ConnectPoint(deviceId, port);
    if (isSuppressedPort(connectPoint)) {
        return Collections.emptySet();
    }
    Set<IpPrefix> subnets = srManager.interfaceService.getInterfacesByPort(connectPoint).stream().flatMap(intf -> intf.ipAddressesList().stream()).map(InterfaceIpAddress::subnetAddress).collect(Collectors.toSet());
    if (subnets.isEmpty()) {
        log.debug(NO_SUBNET, connectPoint);
        return Collections.emptySet();
    }
    return subnets;
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 7 with ConnectPoint

use of org.onosproject.net.ConnectPoint in project trellis-control by opennetworkinglab.

the class HostHandler method processRoutingRule.

/**
 * Populate or revoke a routing rule on given deviceId that matches given ip,
 * set destination mac to given mac, set vlan to given vlan and output to given port.
 *
 * @param deviceId device ID
 * @param port port
 * @param mac mac address
 * @param vlanId VLAN ID
 * @param ip IP address
 * @param revoke true to revoke the rule; false to populate
 * @return future that includes the flow objective if succeeded, null if otherwise
 */
private CompletableFuture<Objective> processRoutingRule(DeviceId deviceId, PortNumber port, MacAddress mac, VlanId vlanId, IpAddress ip, boolean revoke) {
    ConnectPoint location = new ConnectPoint(deviceId, port);
    if (!srManager.deviceConfiguration.inSameSubnet(location, ip)) {
        log.info("{} is not included in the subnet config of {}/{}. Ignored.", ip, deviceId, port);
        return CompletableFuture.completedFuture(null);
    }
    log.info("{} routing rule for {} at {}", revoke ? "Revoking" : "Populating", ip, location);
    if (revoke) {
        return srManager.defaultRoutingHandler.revokeRoute(deviceId, ip.toIpPrefix(), mac, vlanId, port, true);
    } else {
        return srManager.defaultRoutingHandler.populateRoute(deviceId, ip.toIpPrefix(), mac, vlanId, port, true);
    }
}
Also used : ConnectPoint(org.onosproject.net.ConnectPoint)

Example 8 with ConnectPoint

use of org.onosproject.net.ConnectPoint in project trellis-control by opennetworkinglab.

the class HostHandler method isHostInVlanOfPort.

/**
 * Checks if given host located on given device id matches VLAN config of current port.
 *
 * @param host host to check
 * @param deviceId device id to check
 * @param cp current connect point
 * @return true if the host located at deviceId matches the VLAN config on cp
 */
private boolean isHostInVlanOfPort(Host host, DeviceId deviceId, ConnectPoint cp) {
    VlanId internalVlan = srManager.getInternalVlanId(cp);
    Set<VlanId> taggedVlan = srManager.interfaceService.getTaggedVlanId(cp);
    return taggedVlan.contains(host.vlan()) || (internalVlan != null && effectiveLocations(host).stream().filter(l -> l.deviceId().equals(deviceId)).map(srManager::getInternalVlanId).anyMatch(internalVlan::equals));
}
Also used : HostLocation(org.onosproject.net.HostLocation) Tools(org.onlab.util.Tools) Host(org.onosproject.net.Host) PredictableExecutor(org.onlab.util.PredictableExecutor) PortNumber(org.onosproject.net.PortNumber) LoggerFactory(org.slf4j.LoggerFactory) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) CompletableFuture(java.util.concurrent.CompletableFuture) HostService(org.onosproject.net.host.HostService) ConnectPoint(org.onosproject.net.ConnectPoint) HashSet(java.util.HashSet) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Lists(com.google.common.collect.Lists) PhasedRecoveryService(org.onosproject.segmentrouting.phasedrecovery.api.PhasedRecoveryService) HostEvent(org.onosproject.net.host.HostEvent) IpAddress(org.onlab.packet.IpAddress) Logger(org.slf4j.Logger) VlanId(org.onlab.packet.VlanId) Set(java.util.Set) Phase(org.onosproject.segmentrouting.phasedrecovery.api.Phase) ProbeMode(org.onosproject.net.host.ProbeMode) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) EthType(org.onlab.packet.EthType) List(java.util.List) Objective(org.onosproject.net.flowobjective.Objective) Optional(java.util.Optional) MacAddress(org.onlab.packet.MacAddress) DeviceId(org.onosproject.net.DeviceId) IpPrefix(org.onlab.packet.IpPrefix) VlanId(org.onlab.packet.VlanId)

Example 9 with ConnectPoint

use of org.onosproject.net.ConnectPoint in project trellis-control by opennetworkinglab.

the class HostHandler method processIntfVlanUpdatedEvent.

/**
 * Update forwarding objective for unicast bridging and unicast routing.
 * Also check the validity of updated interface configuration on VLAN.
 *
 * @param deviceId device ID that host attaches to
 * @param portNum port number that host attaches to
 * @param vlanId Vlan ID configured on the switch port
 * @param popVlan true to pop Vlan tag at TrafficTreatment, false otherwise
 * @param install true to populate the objective, false to revoke
 */
// TODO Current implementation does not handle dual-homed hosts with auxiliary locations.
void processIntfVlanUpdatedEvent(DeviceId deviceId, PortNumber portNum, VlanId vlanId, boolean popVlan, boolean install) {
    ConnectPoint connectPoint = new ConnectPoint(deviceId, portNum);
    Set<Host> hosts = hostService.getConnectedHosts(connectPoint);
    if (hosts == null || hosts.size() == 0) {
        log.debug("processIntfVlanUpdatedEvent: No hosts connected to {}", connectPoint);
        return;
    }
    List<CompletableFuture<Void>> hostFutures = Lists.newArrayList();
    hosts.forEach(host -> hostFutures.add(hostWorkers.submit(() -> processIntfVlanUpdatedEventInternal(host, deviceId, portNum, vlanId, popVlan, install), host.id().hashCode())));
    // Let's wait for the completion of all hosts
    try {
        CompletableFuture.allOf(hostFutures.toArray(new CompletableFuture[0])).thenApply(objectives -> hostFutures.stream().map(CompletableFuture::join).collect(Collectors.toList())).get();
    } catch (InterruptedException | ExecutionException e) {
        log.warn("Exception caught when executing processIntfVlanUpdatedEvent futures");
        hostFutures.forEach(future -> future.cancel(false));
    }
}
Also used : HostLocation(org.onosproject.net.HostLocation) Tools(org.onlab.util.Tools) Host(org.onosproject.net.Host) PredictableExecutor(org.onlab.util.PredictableExecutor) PortNumber(org.onosproject.net.PortNumber) LoggerFactory(org.slf4j.LoggerFactory) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) CompletableFuture(java.util.concurrent.CompletableFuture) HostService(org.onosproject.net.host.HostService) ConnectPoint(org.onosproject.net.ConnectPoint) HashSet(java.util.HashSet) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Lists(com.google.common.collect.Lists) PhasedRecoveryService(org.onosproject.segmentrouting.phasedrecovery.api.PhasedRecoveryService) HostEvent(org.onosproject.net.host.HostEvent) IpAddress(org.onlab.packet.IpAddress) Logger(org.slf4j.Logger) VlanId(org.onlab.packet.VlanId) Set(java.util.Set) Phase(org.onosproject.segmentrouting.phasedrecovery.api.Phase) ProbeMode(org.onosproject.net.host.ProbeMode) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) EthType(org.onlab.packet.EthType) List(java.util.List) Objective(org.onosproject.net.flowobjective.Objective) Optional(java.util.Optional) MacAddress(org.onlab.packet.MacAddress) DeviceId(org.onosproject.net.DeviceId) IpPrefix(org.onlab.packet.IpPrefix) CompletableFuture(java.util.concurrent.CompletableFuture) Host(org.onosproject.net.Host) ExecutionException(java.util.concurrent.ExecutionException) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 10 with ConnectPoint

use of org.onosproject.net.ConnectPoint in project trellis-control by opennetworkinglab.

the class IcmpHandler method selectRouterIpAddress.

private IpAddress selectRouterIpAddress(IpAddress destIpAddress, ConnectPoint outPort, Set<ConnectPoint> connectPoints) {
    IpAddress routerIpAddress;
    // Let's get first the online connect points
    Set<ConnectPoint> onlineCps = connectPoints.stream().filter(connectPoint -> srManager.deviceService.isAvailable(connectPoint.deviceId())).collect(Collectors.toSet());
    // Check if ping is local
    if (onlineCps.contains(outPort)) {
        routerIpAddress = config.getRouterIpAddress(destIpAddress, outPort.deviceId());
        log.trace("Local ping received from {} - send to {}", destIpAddress, routerIpAddress);
        return routerIpAddress;
    }
    // Check if it comes from a remote device. Loopbacks are sorted comparing byte by byte
    // FIXME if we lose both links from the chosen leaf to spine - ping will fail
    routerIpAddress = onlineCps.stream().filter(onlineCp -> !onlineCp.deviceId().equals(outPort.deviceId())).map(selectedCp -> config.getRouterIpAddress(destIpAddress, selectedCp.deviceId())).filter(Objects::nonNull).sorted().findFirst().orElse(null);
    if (routerIpAddress != null) {
        log.trace("Remote ping received from {} - send to {}", destIpAddress, routerIpAddress);
    } else {
        log.warn("Not found a valid loopback for ping coming from {} - {}", destIpAddress, outPort);
    }
    return routerIpAddress;
}
Also used : DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) ICMP6(org.onlab.packet.ICMP6) Arrays(java.util.Arrays) Interface(org.onosproject.net.intf.Interface) LoggerFactory(org.slf4j.LoggerFactory) HostService(org.onosproject.net.host.HostService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ByteBuffer(java.nio.ByteBuffer) NeighborSolicitation(org.onlab.packet.ndp.NeighborSolicitation) ConnectPoint(org.onosproject.net.ConnectPoint) Ethernet(org.onlab.packet.Ethernet) SegmentRoutingAppConfig(org.onosproject.segmentrouting.config.SegmentRoutingAppConfig) OutboundPacket(org.onosproject.net.packet.OutboundPacket) NeighbourMessageType(org.onosproject.net.neighbour.NeighbourMessageType) IpAddress(org.onlab.packet.IpAddress) NeighbourMessageContext(org.onosproject.net.neighbour.NeighbourMessageContext) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Ip6Address(org.onlab.packet.Ip6Address) Ip4Address(org.onlab.packet.Ip4Address) Logger(org.slf4j.Logger) VlanId(org.onlab.packet.VlanId) Set(java.util.Set) ICMP(org.onlab.packet.ICMP) Collectors(java.util.stream.Collectors) IPv6(org.onlab.packet.IPv6) Objects(java.util.Objects) IPv4(org.onlab.packet.IPv4) MPLS(org.onlab.packet.MPLS) Optional(java.util.Optional) MacAddress(org.onlab.packet.MacAddress) DeviceId(org.onosproject.net.DeviceId) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) Objects(java.util.Objects) IpAddress(org.onlab.packet.IpAddress) ConnectPoint(org.onosproject.net.ConnectPoint)

Aggregations

ConnectPoint (org.onosproject.net.ConnectPoint)536 Test (org.junit.Test)149 DeviceId (org.onosproject.net.DeviceId)125 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)91 Link (org.onosproject.net.Link)88 Set (java.util.Set)86 PortNumber (org.onosproject.net.PortNumber)86 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)83 VlanId (org.onlab.packet.VlanId)78 TrafficSelector (org.onosproject.net.flow.TrafficSelector)75 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)72 Logger (org.slf4j.Logger)71 Port (org.onosproject.net.Port)70 List (java.util.List)69 Ethernet (org.onlab.packet.Ethernet)69 DeviceService (org.onosproject.net.device.DeviceService)67 Collectors (java.util.stream.Collectors)66 MacAddress (org.onlab.packet.MacAddress)64 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)64 Intent (org.onosproject.net.intent.Intent)62