Search in sources :

Example 81 with IpPrefix

use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.

the class SdnIpFib method withdraw.

private void withdraw(ResolvedRoute route) {
    synchronized (this) {
        IpPrefix prefix = route.prefix();
        MultiPointToSinglePointIntent intent = routeIntents.remove(prefix);
        if (intent == null) {
            log.trace("No intent in routeIntents to delete for prefix: {}", prefix);
            return;
        }
        intentSynchronizer.withdraw(intent);
    }
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent)

Example 82 with IpPrefix

use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.

the class SdnIpFib method addInterface.

private void addInterface(Interface intf) {
    synchronized (this) {
        for (Map.Entry<IpPrefix, MultiPointToSinglePointIntent> entry : routeIntents.entrySet()) {
            // Retrieve the IP prefix and affected intent
            IpPrefix prefix = entry.getKey();
            MultiPointToSinglePointIntent intent = entry.getValue();
            // Add new ingress FilteredConnectPoint
            Set<FilteredConnectPoint> ingressFilteredCPs = Sets.newHashSet(intent.filteredIngressPoints());
            // Create the new traffic selector
            TrafficSelector.Builder selector = buildIngressTrafficSelector(intf, prefix);
            // Create the Filtered ConnectPoint and add it to the existing set
            FilteredConnectPoint newIngressFilteredCP = new FilteredConnectPoint(intf.connectPoint(), selector.build());
            ingressFilteredCPs.add(newIngressFilteredCP);
            // Create new intent
            MultiPointToSinglePointIntent newIntent = MultiPointToSinglePointIntent.builder(intent).filteredIngressPoints(ingressFilteredCPs).build();
            routeIntents.put(entry.getKey(), newIntent);
            intentSynchronizer.submit(newIntent);
        }
    }
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

Example 83 with IpPrefix

use of org.onlab.packet.IpPrefix 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)

Example 84 with IpPrefix

use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.

the class SimpleFabricRouting method ipPacketReactiveProcessor.

/**
 * Routes packet reactively.
 */
private void ipPacketReactiveProcessor(PacketContext context, Ethernet ethPkt, ConnectPoint srcCp, IpAddress srcIp, IpAddress dstIp, byte ipProto) {
    /* check reactive handling and forward packet */
    log.trace("ip packet: srcCp={} srcIp={} dstIp={} ipProto={}", srcCp, srcIp, dstIp, ipProto);
    EncapsulationType encap = EncapsulationType.NONE;
    // prefix and nextHop for local Subnet
    IpPrefix srcPrefix = srcIp.toIpPrefix();
    IpPrefix dstPrefix = dstIp.toIpPrefix();
    IpAddress srcNextHop = srcIp;
    IpAddress dstNextHop = dstIp;
    MacAddress treatmentSrcMac = ethPkt.getDestinationMAC();
    int borderRoutePrefixLength = 0;
    boolean updateMac = simpleFabric.isVirtualGatewayMac(ethPkt.getDestinationMAC());
    // check subnet local or route
    FabricSubnet srcSubnet = simpleFabric.fabricSubnet(srcIp);
    if (srcSubnet == null) {
        FabricRoute route = simpleFabric.fabricRoute(srcIp);
        if (route == null) {
            log.warn("unknown srcIp; drop: srcCp={} srcIp={} dstIp={} ipProto={}", srcCp, srcIp, dstIp, ipProto);
            return;
        }
        srcPrefix = route.prefix();
        srcNextHop = route.nextHop();
        borderRoutePrefixLength = route.prefix().prefixLength();
    }
    FabricSubnet dstSubnet = simpleFabric.fabricSubnet(dstIp);
    if (dstSubnet == null) {
        FabricRoute route = simpleFabric.fabricRoute(dstIp);
        if (route == null) {
            log.warn("unknown dstIp; drop: srcCp={} srcIp={} dstIp={} ipProto={}", srcCp, srcIp, dstIp, ipProto);
            return;
        }
        dstPrefix = route.prefix();
        dstNextHop = route.nextHop();
        borderRoutePrefixLength = route.prefix().prefixLength();
    }
    if (dstSubnet != null) {
        // destination is local subnet ip
        if (ALLOW_ETH_ADDRESS_SELECTOR && dstSubnet.equals(srcSubnet)) {
            // NOTE: if ALLOW_ETH_ADDRESS_SELECTOR=false; isForward is always false
            FabricNetwork fabricNetwork = simpleFabric.fabricNetwork(dstSubnet.networkName());
            treatmentSrcMac = ethPkt.getSourceMAC();
            if (fabricNetwork != null && fabricNetwork.isForward()) {
                // NOTE: no reactive route action but do forward packet for L2Forward do not handle packet
                // update mac only if dstMac is virtualGatewayMac, else assume valid mac already for the l2 network
                log.info("LOCAL FORWARD ONLY: " + "srcCp={} srcIp={} dstIp={} srcMac={} dstMac={} vlanId={} ipProto={} updateMac={}", context.inPacket().receivedFrom(), srcIp, dstIp, ethPkt.getSourceMAC(), ethPkt.getDestinationMAC(), ethPkt.getVlanID(), ipProto, updateMac);
                forwardPacketToDstIp(context, dstIp, treatmentSrcMac, updateMac);
                return;
            }
        }
        encap = dstSubnet.encapsulation();
        if (encap == EncapsulationType.NONE && srcSubnet != null) {
            encap = srcSubnet.encapsulation();
        }
    } else {
        // destination is external network
        if (srcSubnet == null) {
            // both are externel network
            log.warn("INVALID PACKET: srcIp and dstIp are both NON-LOCAL: " + "srcCP={} srcIp={} dstIp={} srcMac={} dstMac={} vlanId={} ipProto={} updateMac={}", context.inPacket().receivedFrom(), srcIp, dstIp, ethPkt.getSourceMAC(), ethPkt.getDestinationMAC(), ethPkt.getVlanID(), ipProto, updateMac);
            return;
        }
        encap = srcSubnet.encapsulation();
    }
    log.info("REGI AND FORWARD: " + "srcCP={} srcIp={} dstIp={} srcMac={} dstMac={} vlanId={} ipProto={} updateMac={}", context.inPacket().receivedFrom(), srcIp, dstIp, ethPkt.getSourceMAC(), ethPkt.getDestinationMAC(), ethPkt.getVlanID(), ipProto, updateMac);
    setUpConnectivity(srcCp, ipProto, srcPrefix, dstPrefix, dstNextHop, treatmentSrcMac, encap, updateMac, dstSubnet != null, borderRoutePrefixLength);
    forwardPacketToDstIp(context, dstNextHop, treatmentSrcMac, updateMac);
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) EncapsulationType(org.onosproject.net.EncapsulationType) FabricSubnet(org.onosproject.simplefabric.api.FabricSubnet) IpAddress(org.onlab.packet.IpAddress) MacAddress(org.onlab.packet.MacAddress) FabricNetwork(org.onosproject.simplefabric.api.FabricNetwork) 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) FabricRoute(org.onosproject.simplefabric.api.FabricRoute)

Example 85 with IpPrefix

use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.

the class VbngConfigurationManager method getAvailablePublicIpAddress.

// TODO handle the case: the number of public IP addresses is not enough
// for 1:1 mapping from public IP to private IP.
@Override
public synchronized IpAddress getAvailablePublicIpAddress(IpAddress privateIpAddress) {
    // If there is already a mapping entry for the private IP address,
    // then fetch the public IP address in the mapping entry and return it.
    IpAddress publicIpAddress = ipAddressMap.get(privateIpAddress);
    if (publicIpAddress != null) {
        return publicIpAddress;
    }
    // There is no mapping for the private IP address.
    Iterator<Entry<IpPrefix, Boolean>> prefixes = localPublicIpPrefixes.entrySet().iterator();
    while (prefixes.hasNext()) {
        Entry<IpPrefix, Boolean> prefix = prefixes.next();
        if (!prefix.getValue()) {
            continue;
        }
        if (prefix.getKey().prefixLength() == 32) {
            updateIpPrefixStatus(prefix.getKey(), false);
            publicIpAddress = prefix.getKey().address();
            ipAddressMap.put(privateIpAddress, publicIpAddress);
            return publicIpAddress;
        }
        double prefixLen = prefix.getKey().prefixLength();
        int availableIpNum = (int) Math.pow(2, IpPrefix.MAX_INET_MASK_LENGTH - prefixLen) - 1;
        for (int i = 1; i <= availableIpNum; i++) {
            publicIpAddress = increaseIpAddress(prefix.getKey().address(), i);
            if (publicIpAddress == null) {
                return null;
            }
            if (ipAddressMap.values().contains(publicIpAddress)) {
                continue;
            } else if (i == availableIpNum) {
                // All the IP addresses are assigned out
                // Update this IP prefix status to false
                // Note: in this version we do not consider the
                // IP recycling issue.
                updateIpPrefixStatus(prefix.getKey(), false);
                ipAddressMap.put(privateIpAddress, publicIpAddress);
                return publicIpAddress;
            } else {
                ipAddressMap.put(privateIpAddress, publicIpAddress);
                return publicIpAddress;
            }
        }
    }
    return null;
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) Entry(java.util.Map.Entry) IpAddress(org.onlab.packet.IpAddress) ConnectPoint(org.onosproject.net.ConnectPoint)

Aggregations

IpPrefix (org.onlab.packet.IpPrefix)107 Test (org.junit.Test)37 IpAddress (org.onlab.packet.IpAddress)29 LinkedList (java.util.LinkedList)24 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)22 BgpHeader (org.onosproject.bgpio.types.BgpHeader)22 BgpPathAttributes (org.onosproject.bgpio.protocol.ver4.BgpPathAttributes)21 AsPath (org.onosproject.bgpio.types.AsPath)21 BgpValueType (org.onosproject.bgpio.types.BgpValueType)21 Origin (org.onosproject.bgpio.types.Origin)21 OriginType (org.onosproject.bgpio.types.Origin.OriginType)21 Med (org.onosproject.bgpio.types.Med)20 TrafficSelector (org.onosproject.net.flow.TrafficSelector)20 ProtocolType (org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType)19 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)19 MpReachNlri (org.onosproject.bgpio.types.MpReachNlri)18 LinkStateAttributes (org.onosproject.bgpio.types.LinkStateAttributes)16 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)14 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)14 MacAddress (org.onlab.packet.MacAddress)12