Search in sources :

Example 36 with DeviceId

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

the class IpHandler method processPacketIn.

// ////////////////////
// IPv4 Handling  //
// //////////////////
/**
 * Processes incoming IP packets.
 *
 * If it is an IP packet for known host, then forward it to the host.
 * If it is an IP packet for unknown host in subnet, then send an ARP request
 * to the subnet.
 *
 * @param pkt incoming packet
 * @param connectPoint the target device
 */
public void processPacketIn(IPv4 pkt, ConnectPoint connectPoint) {
    DeviceId deviceId = connectPoint.deviceId();
    Ip4Address destinationAddress = Ip4Address.valueOf(pkt.getDestinationAddress());
    // IP packet for know hosts
    if (!srManager.hostService.getHostsByIp(destinationAddress).isEmpty()) {
        forwardPackets(deviceId, destinationAddress);
    // IP packet for unknown host in one of the configured subnets of the router
    } else if (config.inSameSubnet(deviceId, destinationAddress)) {
        srManager.arpHandler.sendArpRequest(deviceId, destinationAddress, connectPoint);
    // IP packets for unknown host
    } else {
        log.debug("IPv4 packet for unknown host {} which is not in the subnet", destinationAddress);
    // Do nothing
    }
}
Also used : DeviceId(org.onosproject.net.DeviceId) Ip4Address(org.onlab.packet.Ip4Address)

Example 37 with DeviceId

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

the class LinkHandler method updateHostPorts.

/**
 * Administratively enables or disables edge ports if the link that was
 * added or removed was the only uplink port from an edge device. Edge ports
 * that belong to dual-homed hosts are always processed. In addition,
 * single-homed host ports are optionally processed depending on the
 * singleHomedDown property.
 *
 * @param link the link to be processed
 * @param added true if link was added, false if link was removed
 */
private void updateHostPorts(Link link, boolean added) {
    // Topology has only a single pair of leaves
    if (srManager.getInfraDeviceIds().isEmpty()) {
        log.debug("No spine configured. Not updating edge port for {} {}", link, added ? "add" : "remove");
        return;
    }
    DeviceConfiguration devConfig = srManager.deviceConfiguration;
    if (added) {
        try {
            if (!devConfig.isEdgeDevice(link.src().deviceId()) || devConfig.isEdgeDevice(link.dst().deviceId())) {
                return;
            }
        } catch (DeviceConfigNotFoundException e) {
            log.warn("Unable to determine if link is a valid uplink" + e.getMessage());
        }
        // re-enable previously disabled ports on this edge-device if any
        Set<PortNumber> p = downedPortStore.remove(link.src().deviceId());
        if (p != null) {
            log.warn("Link src {} --> dst {} added is an edge-device uplink, " + "enabling dual homed ports if any: {}", link.src().deviceId(), link.dst().deviceId(), (p.isEmpty()) ? "no ports" : p);
            p.forEach(pnum -> srManager.deviceAdminService.changePortState(link.src().deviceId(), pnum, true));
        }
    } else {
        // If the device does not have a pair device - skip
        DeviceId dev = link.src().deviceId();
        if (getPairDeviceIdOrNull(dev) == null) {
            log.info("Device {} does not have pair device " + "not disabling access port", dev);
            return;
        }
        // Verify if last uplink
        if (!lastUplink(link)) {
            return;
        }
        // find dual homed hosts on this dev to disable
        Set<PortNumber> dp = srManager.hostHandler.getDualHomedHostPorts(dev);
        log.warn("Link src {} --> dst {} removed was the last uplink, " + "disabling  dual homed ports:  {}", dev, link.dst().deviceId(), (dp.isEmpty()) ? "no ports" : dp);
        dp.forEach(pnum -> srManager.deviceAdminService.changePortState(dev, pnum, false));
        if (srManager.singleHomedDown) {
            // get all configured ports and down them if they haven't already
            // been downed
            srManager.deviceService.getPorts(dev).stream().filter(p -> p.isEnabled() && !dp.contains(p.number())).filter(p -> srManager.interfaceService.isConfigured(new ConnectPoint(dev, p.number()))).filter(p -> !srManager.deviceConfiguration.isPairLocalPort(dev, p.number())).forEach(p -> {
                log.warn("Last uplink gone src {} -> dst {} .. removing " + "configured port {}", p.number());
                srManager.deviceAdminService.changePortState(dev, p.number(), false);
                dp.add(p.number());
            });
        }
        if (!dp.isEmpty()) {
            // update global store
            Set<PortNumber> p = downedPortStore.get(dev);
            if (p == null) {
                p = dp;
            } else {
                p.addAll(dp);
            }
            downedPortStore.put(link.src().deviceId(), p);
        }
    }
}
Also used : DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) Logger(org.slf4j.Logger) HostLocation(org.onosproject.net.HostLocation) Device(org.onosproject.net.Device) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PortNumber(org.onosproject.net.PortNumber) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) EventuallyConsistentMapBuilder(org.onosproject.store.service.EventuallyConsistentMapBuilder) WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) Collectors(java.util.stream.Collectors) Link(org.onosproject.net.Link) Sets(com.google.common.collect.Sets) ConnectPoint(org.onosproject.net.ConnectPoint) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) DefaultGroupHandler(org.onosproject.segmentrouting.grouphandler.DefaultGroupHandler) Map(java.util.Map) Entry(java.util.Map.Entry) LinkService(org.onosproject.net.link.LinkService) EventuallyConsistentMap(org.onosproject.store.service.EventuallyConsistentMap) DeviceId(org.onosproject.net.DeviceId) DeviceId(org.onosproject.net.DeviceId) PortNumber(org.onosproject.net.PortNumber) ConnectPoint(org.onosproject.net.ConnectPoint) DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException)

Example 38 with DeviceId

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

the class LinkHandler method avoidLink.

/**
 * Determines if the given link should be avoided in routing calculations by
 * policy or design.
 *
 * @param link the infrastructure link being queried
 * @return true if link should be avoided
 */
boolean avoidLink(Link link) {
    // XXX currently only avoids all pair-links. In the future can be
    // extended to avoid any generic link
    DeviceId src = link.src().deviceId();
    PortNumber srcPort = link.src().port();
    DeviceConfiguration devConfig = srManager.deviceConfiguration;
    if (devConfig == null || !devConfig.isConfigured(src)) {
        log.warn("Device {} not configured..cannot avoid link {}", src, link);
        return false;
    }
    DeviceId pairDev;
    PortNumber pairLocalPort, pairRemotePort = null;
    try {
        pairDev = devConfig.getPairDeviceId(src);
        pairLocalPort = devConfig.getPairLocalPort(src);
        if (pairDev != null) {
            pairRemotePort = devConfig.getPairLocalPort(pairDev);
        }
    } catch (DeviceConfigNotFoundException e) {
        log.warn("Pair dev for dev {} not configured..cannot avoid link {}", src, link);
        return false;
    }
    return srcPort.equals(pairLocalPort) && link.dst().deviceId().equals(pairDev) && link.dst().port().equals(pairRemotePort);
}
Also used : DeviceId(org.onosproject.net.DeviceId) PortNumber(org.onosproject.net.PortNumber) DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException)

Example 39 with DeviceId

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

the class PolicyHandler method removePolicy.

/**
 * Removes the policy given.
 *
 * @param policyInfo policy information to remove
 * @return POLICY_NOT_FOUND if the policy to remove does not exists,
 * SUCCESS if it is removed successfully
 */
public Result removePolicy(Policy policyInfo) {
    if (policyStore.get(policyInfo.id()) != null) {
        Policy policy = policyStore.get(policyInfo.id());
        if (policy.type() == Policy.Type.TUNNEL_FLOW) {
            TunnelPolicy tunnelPolicy = (TunnelPolicy) policy;
            Tunnel tunnel = tunnelHandler.getTunnel(tunnelPolicy.tunnelId());
            ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective.builder().fromApp(appId).makePermanent().withSelector(buildSelector(policy)).withPriority(tunnelPolicy.priority()).nextStep(tunnel.groupId()).withFlag(ForwardingObjective.Flag.VERSATILE);
            DeviceId source = deviceConfiguration.getDeviceId(tunnel.labelIds().get(0));
            flowObjectiveService.forward(source, fwdBuilder.remove());
            policyStore.remove(policyInfo.id());
        }
    } else {
        log.warn("Policy {} was not found", policyInfo.id());
        return Result.POLICY_NOT_FOUND;
    }
    return Result.SUCCESS;
}
Also used : DeviceId(org.onosproject.net.DeviceId) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective)

Example 40 with DeviceId

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

the class PortAuthTracker method radiusAuthorize.

/**
 * Radius has authorized the supplicant at this connect point. If
 * we are tracking this port, clear the blocking flow and mark the
 * port as authorized.
 *
 * @param connectPoint supplicant connect point
 */
void radiusAuthorize(ConnectPoint connectPoint) {
    DeviceId d = connectPoint.deviceId();
    PortNumber p = connectPoint.port();
    if (configured(d, p)) {
        clearBlockingFlow(d, p);
        markAsAuthenticated(d, p);
    }
}
Also used : DeviceId(org.onosproject.net.DeviceId) PortNumber(org.onosproject.net.PortNumber)

Aggregations

DeviceId (org.onosproject.net.DeviceId)782 List (java.util.List)178 PortNumber (org.onosproject.net.PortNumber)170 Collectors (java.util.stream.Collectors)152 ConnectPoint (org.onosproject.net.ConnectPoint)152 Set (java.util.Set)138 DeviceService (org.onosproject.net.device.DeviceService)122 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)118 ArrayList (java.util.ArrayList)115 VlanId (org.onlab.packet.VlanId)115 Logger (org.slf4j.Logger)114 Collections (java.util.Collections)109 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)109 Device (org.onosproject.net.Device)107 Collection (java.util.Collection)106 Test (org.junit.Test)104 CoreService (org.onosproject.core.CoreService)103 FlowRule (org.onosproject.net.flow.FlowRule)101 ImmutableSet (com.google.common.collect.ImmutableSet)99 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)96