Search in sources :

Example 66 with Interface

use of org.onosproject.net.intf.Interface in project onos by opennetworkinglab.

the class DirectHostManager method sendQueued.

private void sendQueued(IpAddress ipAddress, MacAddress macAddress) {
    log.debug("Sending queued packets for {} ({})", ipAddress, macAddress);
    ipPacketCache.asMap().computeIfPresent(ipAddress, (ip, packets) -> {
        packets.forEach(ipPackets -> {
            Interface egressInterface = interfaceService.getMatchingInterface(ipAddress);
            if (egressInterface == null) {
                log.info("No egress interface found for {}", ipAddress);
                return;
            }
            // According to the type of the address we set proper
            // protocol.
            transformAndSend(ipPackets, ipAddress.isIp4() ? Ethernet.TYPE_IPV4 : Ethernet.TYPE_IPV6, egressInterface, macAddress);
        });
        return null;
    });
}
Also used : Interface(org.onosproject.net.intf.Interface)

Example 67 with Interface

use of org.onosproject.net.intf.Interface in project onos by opennetworkinglab.

the class SimpleFabricManager method refresh.

// Set up from configuration
// returns found isDirty and refresh listeners are called (true) or not (false)
private boolean refresh() {
    log.debug("simple fabric refresh");
    boolean dirty = false;
    SimpleFabricConfig config = configService.getConfig(coreService.registerApplication(APP_ID), SimpleFabricConfig.class);
    if (config == null) {
        log.debug("No simple fabric config available!");
        return false;
    }
    // fabricNetworks
    Set<FabricNetwork> newFabricNetworks = new HashSet<>();
    Set<Interface> newInterfaces = new HashSet<>();
    for (FabricNetwork newFabricNetworkConfig : config.fabricNetworks()) {
        FabricNetwork newFabricNetwork = DefaultFabricNetwork.of(newFabricNetworkConfig);
        // fill up interfaces and Hosts with active port only
        for (String ifaceName : newFabricNetworkConfig.interfaceNames()) {
            Interface iface = getInterfaceByName(ifaceName);
            if (iface != null && deviceService.isAvailable(iface.connectPoint().deviceId())) {
                newFabricNetwork.addInterface(iface);
                newInterfaces.add(iface);
            }
        }
        for (Host host : hostService.getHosts()) {
            // consider host with ip only
            if (!host.ipAddresses().isEmpty()) {
                Interface iface = findAvailableDeviceHostInterface(host);
                if (iface != null && newFabricNetwork.contains(iface)) {
                    newFabricNetwork.addHost(host);
                }
            }
        }
        newFabricNetwork.setDirty(true);
        // update newFabricNetwork's isDirty flags if same entry already exists
        for (FabricNetwork prevFabricNetwork : fabricNetworks) {
            if (prevFabricNetwork.equals(newFabricNetwork)) {
                newFabricNetwork.setDirty(prevFabricNetwork.isDirty());
                break;
            }
        }
        newFabricNetworks.add(newFabricNetwork);
    }
    if (!fabricNetworks.equals(newFabricNetworks)) {
        fabricNetworks = newFabricNetworks;
        dirty = true;
    }
    if (!networkInterfaces.equals(newInterfaces)) {
        networkInterfaces = newInterfaces;
        dirty = true;
    }
    // default Fabric Subnets
    Set<FabricSubnet> newFabricSubnets = config.fabricSubnets();
    InvertedRadixTree<FabricSubnet> newIp4SubnetTable = new ConcurrentInvertedRadixTree<>(new DefaultByteArrayNodeFactory());
    InvertedRadixTree<FabricSubnet> newIp6SubnetTable = new ConcurrentInvertedRadixTree<>(new DefaultByteArrayNodeFactory());
    Map<IpAddress, MacAddress> newVirtualGatewayIpMacMap = Maps.newConcurrentMap();
    for (FabricSubnet subnet : newFabricSubnets) {
        if (subnet.prefix().isIp4()) {
            newIp4SubnetTable.put(createBinaryString(subnet.prefix()), subnet);
        } else {
            newIp6SubnetTable.put(createBinaryString(subnet.prefix()), subnet);
        }
        newVirtualGatewayIpMacMap.put(subnet.gatewayIp(), subnet.gatewayMac());
    }
    if (!fabricSubnets.equals(newFabricSubnets)) {
        fabricSubnets = newFabricSubnets;
        ip4SubnetTable = newIp4SubnetTable;
        ip6SubnetTable = newIp6SubnetTable;
        dirty = true;
    }
    if (!virtualGatewayIpMacMap.equals(newVirtualGatewayIpMacMap)) {
        virtualGatewayIpMacMap = newVirtualGatewayIpMacMap;
        dirty = true;
    }
    // fabricRoutes config handling
    Set<FabricRoute> newFabricRoutes = config.fabricRoutes();
    if (!fabricRoutes.equals(newFabricRoutes)) {
        InvertedRadixTree<FabricRoute> newIp4BorderRouteTable = new ConcurrentInvertedRadixTree<>(new DefaultByteArrayNodeFactory());
        InvertedRadixTree<FabricRoute> newIp6BorderRouteTable = new ConcurrentInvertedRadixTree<>(new DefaultByteArrayNodeFactory());
        for (FabricRoute route : newFabricRoutes) {
            if (route.prefix().isIp4()) {
                newIp4BorderRouteTable.put(createBinaryString(route.prefix()), route);
            } else {
                newIp6BorderRouteTable.put(createBinaryString(route.prefix()), route);
            }
        }
        fabricRoutes = newFabricRoutes;
        ip4BorderRouteTable = newIp4BorderRouteTable;
        ip6BorderRouteTable = newIp6BorderRouteTable;
        dirty = true;
    }
    // notify to SimpleFabric listeners
    if (dirty) {
        log.info("simple fabric refresh; notify events");
        process(new SimpleFabricEvent(SimpleFabricEvent.Type.SIMPLE_FABRIC_UPDATED, "updated"));
    }
    return dirty;
}
Also used : DefaultByteArrayNodeFactory(com.googlecode.concurrenttrees.radix.node.concrete.DefaultByteArrayNodeFactory) Host(org.onosproject.net.Host) RouteTools.createBinaryString(org.onosproject.routeservice.RouteTools.createBinaryString) MacAddress(org.onlab.packet.MacAddress) SimpleFabricEvent(org.onosproject.simplefabric.api.SimpleFabricEvent) FabricNetwork(org.onosproject.simplefabric.api.FabricNetwork) FabricRoute(org.onosproject.simplefabric.api.FabricRoute) FabricSubnet(org.onosproject.simplefabric.api.FabricSubnet) IpAddress(org.onlab.packet.IpAddress) ConcurrentInvertedRadixTree(com.googlecode.concurrenttrees.radixinverted.ConcurrentInvertedRadixTree) Interface(org.onosproject.net.intf.Interface) HashSet(java.util.HashSet)

Example 68 with Interface

use of org.onosproject.net.intf.Interface in project onos by opennetworkinglab.

the class SimpleFabricManager method requestMac.

@Override
public boolean requestMac(IpAddress ip) {
    FabricSubnet fabricSubnet = fabricSubnet(ip);
    if (fabricSubnet == null) {
        log.warn("simple fabric request mac failed for unknown fabricSubnet: {}", ip);
        return false;
    }
    FabricNetwork fabricNetwork = fabricNetwork(fabricSubnet.networkName());
    if (fabricNetwork == null) {
        log.warn("simple fabric request mac failed for unknown fabricNetwork name {}: {}", fabricSubnet.networkName(), ip);
        return false;
    }
    log.debug("simple fabric send request mac fabricNetwork {}: {}", fabricNetwork.name(), ip);
    for (Interface iface : fabricNetwork.interfaces()) {
        Ethernet neighbourReq;
        if (ip.isIp4()) {
            neighbourReq = ARP.buildArpRequest(fabricSubnet.gatewayMac().toBytes(), fabricSubnet.gatewayIp().toOctets(), ip.toOctets(), iface.vlan().toShort());
        } else {
            byte[] soliciteIp = IPv6.getSolicitNodeAddress(ip.toOctets());
            neighbourReq = NeighborSolicitation.buildNdpSolicit(ip.getIp6Address(), fabricSubnet.gatewayIp().getIp6Address(), Ip6Address.valueOf(soliciteIp), MacAddress.valueOf(fabricSubnet.gatewayMac().toBytes()), MacAddress.valueOf(IPv6.getMCastMacAddress(soliciteIp)), iface.vlan());
        }
        TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(iface.connectPoint().port()).build();
        OutboundPacket packet = new DefaultOutboundPacket(iface.connectPoint().deviceId(), treatment, ByteBuffer.wrap(neighbourReq.serialize()));
        packetService.emit(packet);
    }
    return true;
}
Also used : FabricSubnet(org.onosproject.simplefabric.api.FabricSubnet) Ethernet(org.onlab.packet.Ethernet) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) FabricNetwork(org.onosproject.simplefabric.api.FabricNetwork) Interface(org.onosproject.net.intf.Interface) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket)

Example 69 with Interface

use of org.onosproject.net.intf.Interface in project onos by opennetworkinglab.

the class SimpleFabricNeighbour method refresh.

/**
 * Registers neighbour handler to all available interfaces.
 */
protected void refresh() {
    Set<Interface> interfaces = interfaceService.getInterfaces();
    // check for new interfaces
    for (Interface intf : interfaces) {
        if (!monitoredInterfaces.contains(intf) && simpleFabric.isFabricNetworkInterface(intf)) {
            log.info("simple fabric neighbour register handler: {}", intf);
            neighbourService.registerNeighbourHandler(intf, neighbourHandler, appId);
            monitoredInterfaces.add(intf);
        } else {
            log.debug("simple fabric neighobur unknown interface: {}", intf);
        }
    }
    // check for removed interfaces
    Set<Interface> monitoredInterfacesToBeRemoved = new HashSet<>();
    for (Interface intf : monitoredInterfaces) {
        if (!interfaces.contains(intf)) {
            log.info("simple fabric neighbour unregister handler: {}", intf);
            neighbourService.unregisterNeighbourHandler(intf, neighbourHandler, appId);
            monitoredInterfacesToBeRemoved.add(intf);
        }
    }
    for (Interface intf : monitoredInterfacesToBeRemoved) {
        monitoredInterfaces.remove(intf);
    }
}
Also used : Interface(org.onosproject.net.intf.Interface) HashSet(java.util.HashSet)

Example 70 with Interface

use of org.onosproject.net.intf.Interface in project onos by opennetworkinglab.

the class SimpleFabricRouting method generateLocalSubnetIpBctFlowRule.

private FlowRule generateLocalSubnetIpBctFlowRule(DeviceId deviceId, IpPrefix prefix, FabricNetwork fabricNetwork) {
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    IpPrefix bctPrefix;
    if (prefix.isIp4()) {
        bctPrefix = Ip4Prefix.valueOf(prefix.getIp4Prefix().address().toInt() | ~Ip4Address.makeMaskPrefix(prefix.prefixLength()).toInt(), Ip4Address.BIT_LENGTH);
        selector.matchEthType(Ethernet.TYPE_IPV4);
        selector.matchIPDst(bctPrefix);
    } else {
        byte[] p = prefix.getIp6Prefix().address().toOctets();
        byte[] m = Ip6Address.makeMaskPrefix(prefix.prefixLength()).toOctets();
        for (int i = 0; i < p.length; i++) {
            p[i] |= ~m[i];
        }
        bctPrefix = Ip6Prefix.valueOf(p, Ip6Address.BIT_LENGTH);
        selector.matchEthType(Ethernet.TYPE_IPV6);
        selector.matchIPv6Dst(bctPrefix);
    }
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    Set<ConnectPoint> newEgressPoints = new HashSet<>();
    for (Interface iface : fabricNetwork.interfaces()) {
        if (iface.connectPoint().deviceId().equals(deviceId)) {
            treatment.setOutput(iface.connectPoint().port());
        }
    }
    FlowRule rule = DefaultFlowRule.builder().forDevice(deviceId).withPriority(reactivePriority(true, true, bctPrefix.prefixLength())).withSelector(selector.build()).withTreatment(treatment.build()).fromApp(appId).makePermanent().forTable(0).build();
    return rule;
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) HashedPathSelectionConstraint(org.onosproject.net.intent.constraint.HashedPathSelectionConstraint) ConnectPoint(org.onosproject.net.ConnectPoint) Constraint(org.onosproject.net.intent.Constraint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) PartialFailureConstraint(org.onosproject.net.intent.constraint.PartialFailureConstraint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) Interface(org.onosproject.net.intf.Interface) HashSet(java.util.HashSet)

Aggregations

Interface (org.onosproject.net.intf.Interface)92 ConnectPoint (org.onosproject.net.ConnectPoint)51 MacAddress (org.onlab.packet.MacAddress)35 VlanId (org.onlab.packet.VlanId)34 InterfaceIpAddress (org.onosproject.net.host.InterfaceIpAddress)32 Ethernet (org.onlab.packet.Ethernet)28 IpAddress (org.onlab.packet.IpAddress)28 ArrayList (java.util.ArrayList)26 DeviceId (org.onosproject.net.DeviceId)26 Host (org.onosproject.net.Host)25 InterfaceService (org.onosproject.net.intf.InterfaceService)25 Logger (org.slf4j.Logger)25 Set (java.util.Set)23 TrafficSelector (org.onosproject.net.flow.TrafficSelector)23 LoggerFactory (org.slf4j.LoggerFactory)23 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)22 Test (org.junit.Test)21 ApplicationId (org.onosproject.core.ApplicationId)21 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)20 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)20