Search in sources :

Example 26 with IpPrefix

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

the class OfdpaPipelineTraceable method matchIp.

// Checks if the packet has an dst or src IP and if that IP matches the subnet of the ip criterion
// TODO Candidate for an AbstractBehavior implementation
private boolean matchIp(TrafficSelector packet, IPCriterion criterion) {
    IPCriterion matchCriterion = (IPCriterion) packet.getCriterion(criterion.type());
    // if the packet does not have an IPv4 or IPv6 criterion we return true
    if (matchCriterion == null) {
        return false;
    }
    log.debug("Checking if {} is under {}", matchCriterion.ip(), criterion.ip());
    IpPrefix subnet = criterion.ip();
    return subnet.contains(matchCriterion.ip().address());
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion)

Example 27 with IpPrefix

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

the class ScaleTestManager method createRoutes.

// Creates the specified number of random routes. Such routes are generated
// using random IP prefices with next hop being an IP address of a randomly
// chosen hosts.
private void createRoutes(int routeCount) {
    List<Host> hosts = ImmutableList.copyOf(hostAdminService.getHosts());
    ImmutableSet.Builder<Route> routes = ImmutableSet.builder();
    for (int i = 0; i < routeCount; i++) {
        IpPrefix prefix = randomIp().toIpPrefix();
        IpAddress nextHop = randomIp(hosts);
        routes.add(new Route(Route.Source.STATIC, prefix, nextHop));
    }
    routeAdminService.update(routes.build());
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) ImmutableSet(com.google.common.collect.ImmutableSet) Host(org.onosproject.net.Host) IpAddress(org.onlab.packet.IpAddress) Route(org.onosproject.routeservice.Route)

Example 28 with IpPrefix

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

the class LinkCollectionCompiler method updateBuilder.

/**
 * Update the selector builder using a L3 instruction.
 *
 * @param builder the builder to update
 * @param l3instruction the l3 instruction to use
 */
private void updateBuilder(TrafficSelector.Builder builder, L3ModificationInstruction l3instruction) {
    // TODO check ethernet proto
    switch(l3instruction.subtype()) {
        case IPV4_SRC:
        case IPV4_DST:
        case IPV6_SRC:
        case IPV6_DST:
            ModIPInstruction ipInstr = (ModIPInstruction) l3instruction;
            // TODO check if ip falls in original prefix
            IpPrefix prefix = ipInstr.ip().toIpPrefix();
            switch(ipInstr.subtype()) {
                case IPV4_SRC:
                    builder.matchIPSrc(prefix);
                    break;
                case IPV4_DST:
                    builder.matchIPSrc(prefix);
                    break;
                case IPV6_SRC:
                    builder.matchIPv6Src(prefix);
                    break;
                case IPV6_DST:
                    builder.matchIPv6Dst(prefix);
                    break;
                default:
                    throw new IntentCompilationException(UNSUPPORTED_IP_SUBTYPE);
            }
            break;
        case IPV6_FLABEL:
            ModIPv6FlowLabelInstruction ipFlowInstr = (ModIPv6FlowLabelInstruction) l3instruction;
            builder.matchIPv6FlowLabel(ipFlowInstr.flowLabel());
            break;
        case DEC_TTL:
            // no-op
            break;
        case TTL_OUT:
            // no-op
            break;
        case TTL_IN:
            // no-op
            break;
        case ARP_SPA:
            ModArpIPInstruction srcArpIpInstr = (ModArpIPInstruction) l3instruction;
            if (srcArpIpInstr.ip().isIp4()) {
                builder.matchArpSpa((Ip4Address) srcArpIpInstr.ip());
            } else {
                throw new IntentCompilationException(UNSUPPORTED_ARP);
            }
            break;
        case ARP_SHA:
            ModArpEthInstruction srcArpEthInstr = (ModArpEthInstruction) l3instruction;
            builder.matchArpSha(srcArpEthInstr.mac());
            break;
        case ARP_TPA:
            ModArpIPInstruction dstArpIpInstr = (ModArpIPInstruction) l3instruction;
            if (dstArpIpInstr.ip().isIp4()) {
                builder.matchArpTpa((Ip4Address) dstArpIpInstr.ip());
            } else {
                throw new IntentCompilationException(UNSUPPORTED_ARP);
            }
            break;
        case ARP_THA:
            ModArpEthInstruction dstArpEthInstr = (ModArpEthInstruction) l3instruction;
            builder.matchArpTha(dstArpEthInstr.mac());
            break;
        case ARP_OP:
            ModArpOpInstruction arpOpInstr = (ModArpOpInstruction) l3instruction;
            // FIXME is the long to int cast safe?
            builder.matchArpOp((int) arpOpInstr.op());
            break;
        default:
            throw new IntentCompilationException(UNSUPPORTED_L3);
    }
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) ModArpEthInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpEthInstruction) ModIPv6FlowLabelInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction) IntentCompilationException(org.onosproject.net.intent.IntentCompilationException) ModArpOpInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpOpInstruction) ModIPInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction) ModArpIPInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpIPInstruction)

Example 29 with IpPrefix

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

the class DistributedFpmPrefixStore method activated.

@Activate
protected void activated() {
    dhcpFpmRecords = storageService.<IpPrefix, FpmRecord>eventuallyConsistentMapBuilder().withName("DHCP-FPM-Records").withTimestampProvider((k, v) -> new WallClockTimestamp()).withSerializer(APP_KRYO).withPersistence().build();
    listener = new InternalMapListener();
    dhcpFpmRecords.addListener(listener);
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) FpmRecord(org.onosproject.routing.fpm.api.FpmRecord) Activate(org.osgi.service.component.annotations.Activate)

Example 30 with IpPrefix

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

the class FpmManager method fpmMessage.

private void fpmMessage(FpmPeer peer, FpmHeader fpmMessage) {
    if (fpmMessage.type() == FpmHeader.FPM_TYPE_KEEPALIVE) {
        return;
    }
    Netlink netlink = fpmMessage.netlink();
    RtNetlink rtNetlink = netlink.rtNetlink();
    if (log.isTraceEnabled()) {
        log.trace("Received FPM message: {}", fpmMessage);
    }
    if (!(rtNetlink.protocol() == RtProtocol.ZEBRA || rtNetlink.protocol() == RtProtocol.UNSPEC)) {
        log.trace("Ignoring non-zebra route");
        return;
    }
    IpAddress dstAddress = null;
    IpAddress gateway = null;
    for (RouteAttribute attribute : rtNetlink.attributes()) {
        if (attribute.type() == RouteAttribute.RTA_DST) {
            RouteAttributeDst raDst = (RouteAttributeDst) attribute;
            dstAddress = raDst.dstAddress();
        } else if (attribute.type() == RouteAttribute.RTA_GATEWAY) {
            RouteAttributeGateway raGateway = (RouteAttributeGateway) attribute;
            gateway = raGateway.gateway();
        }
    }
    if (dstAddress == null) {
        log.error("Dst address missing!");
        return;
    }
    IpPrefix prefix = IpPrefix.valueOf(dstAddress, rtNetlink.dstLength());
    // Ignore routes that we sent.
    if (gateway != null && ((prefix.isIp4() && pdPushNextHopIPv4 != null && pdPushNextHopIPv4.contains(gateway.getIp4Address())) || (prefix.isIp6() && pdPushNextHopIPv6 != null && pdPushNextHopIPv6.contains(gateway.getIp6Address())))) {
        if (routeInDhcpStore(prefix) || routeInRipStore(prefix)) {
            return;
        }
    }
    List<Route> updates = new LinkedList<>();
    List<Route> withdraws = new LinkedList<>();
    Route route;
    switch(netlink.type()) {
        case RTM_NEWROUTE:
            if (gateway == null) {
                // We ignore interface routes with no gateway for now.
                return;
            }
            route = new Route(Route.Source.FPM, prefix, gateway, clusterService.getLocalNode().id());
            Route oldRoute = fpmRoutes.get(peer).put(prefix, route);
            if (oldRoute != null) {
                log.trace("Swapping {} with {}", oldRoute, route);
                withdraws.add(oldRoute);
            }
            updates.add(route);
            break;
        case RTM_DELROUTE:
            Route existing = fpmRoutes.get(peer).remove(prefix);
            if (existing == null) {
                log.warn("Got delete for non-existent prefix");
                return;
            }
            route = new Route(Route.Source.FPM, prefix, existing.nextHop(), clusterService.getLocalNode().id());
            withdraws.add(route);
            break;
        case RTM_GETROUTE:
        default:
            break;
    }
    updateRouteStore(updates, withdraws);
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) Netlink(org.onosproject.routing.fpm.protocol.Netlink) RtNetlink(org.onosproject.routing.fpm.protocol.RtNetlink) RouteAttributeDst(org.onosproject.routing.fpm.protocol.RouteAttributeDst) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) IpAddress(org.onlab.packet.IpAddress) RouteAttributeGateway(org.onosproject.routing.fpm.protocol.RouteAttributeGateway) RouteAttribute(org.onosproject.routing.fpm.protocol.RouteAttribute) RtNetlink(org.onosproject.routing.fpm.protocol.RtNetlink) Route(org.onosproject.routeservice.Route) LinkedList(java.util.LinkedList)

Aggregations

IpPrefix (org.onlab.packet.IpPrefix)131 Test (org.junit.Test)42 IpAddress (org.onlab.packet.IpAddress)36 LinkedList (java.util.LinkedList)24 TrafficSelector (org.onosproject.net.flow.TrafficSelector)24 MacAddress (org.onlab.packet.MacAddress)23 ConnectPoint (org.onosproject.net.ConnectPoint)23 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 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)21 Med (org.onosproject.bgpio.types.Med)20 VlanId (org.onlab.packet.VlanId)19 ProtocolType (org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType)19 MpReachNlri (org.onosproject.bgpio.types.MpReachNlri)18 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)18