Java Code Examples for org.onlab.packet.Ethernet#TYPE_IPV6

The following examples show how to use org.onlab.packet.Ethernet#TYPE_IPV6 . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FilteringObjectiveTranslator.java    From onos with Apache License 2.0 6 votes vote down vote up
private FlowRule maskedFwdClassifierRule(
        PortNumber inPort, MacAddress dstMac, MacAddress dstMacMask,
        FilteringObjective obj)
        throws FabricPipelinerException {
    final TrafficTreatment treatment;
    final short ethType;
    if (dstMac.equals(MacAddress.IPV4_MULTICAST)
            && dstMacMask.equals(MacAddress.IPV4_MULTICAST_MASK)) {
        treatment = fwdClassifierTreatment(FWD_IPV4_ROUTING);
        ethType = Ethernet.TYPE_IPV4;
    } else if (dstMac.equals(MacAddress.IPV6_MULTICAST)
            && dstMacMask.equals(MacAddress.IPV6_MULTICAST_MASK)) {
        treatment = fwdClassifierTreatment(FWD_IPV6_ROUTING);
        ethType = Ethernet.TYPE_IPV6;
    } else {
        throw new FabricPipelinerException(format(
                "Unsupported masked Ethernet address for fwd " +
                        "classifier rule (mac=%s, mask=%s)",
                dstMac, dstMacMask));
    }
    return fwdClassifierRule(inPort, ethType, dstMac, dstMacMask, treatment, obj);
}
 
Example 2
Source File: RouterAdvertisementManager.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void process(PacketContext context) {
    if (context.isHandled()) {
        return;
    }

    // Ensure packet is IPv6 Solicited RA
    InboundPacket pkt = context.inPacket();
    Ethernet ethernet = pkt.parsed();
    if ((ethernet == null) || (ethernet.getEtherType() != Ethernet.TYPE_IPV6)) {
        return;
    }
    IPv6 ipv6Packet = (IPv6) ethernet.getPayload();
    if (ipv6Packet.getNextHeader() != IPv6.PROTOCOL_ICMP6) {
        return;
    }
    ICMP6 icmp6Packet = (ICMP6) ipv6Packet.getPayload();
    if (icmp6Packet.getIcmpType() != ICMP6.ROUTER_SOLICITATION) {
        return;
    }

    // Start solicited-RA handling thread
    SolicitedRAWorkerThread sraWorkerThread = new SolicitedRAWorkerThread(pkt);
    executors.schedule(sraWorkerThread, 0, TimeUnit.SECONDS);
}
 
Example 3
Source File: Icmp6PacketClassifier.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public boolean match(PacketContext packet) {
    Ethernet eth = packet.inPacket().parsed();

    if (eth.getEtherType() == Ethernet.TYPE_IPV6) {
        IPv6 ipv6Packet = (IPv6) eth.getPayload();

        if (ipv6Packet.getNextHeader() == IPv6.PROTOCOL_ICMP6) {
            ICMP6 icmp6Packet = (ICMP6) ipv6Packet.getPayload();
            if (icmp6Packet.getIcmpType() == ICMP6.ECHO_REQUEST) {
                return true;
            }
        }
    }
    return false;
}
 
Example 4
Source File: NAPacketClassifier.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public boolean match(PacketContext packet) {

    Ethernet eth = packet.inPacket().parsed();

    if (eth.getEtherType() == Ethernet.TYPE_IPV6) {
        IPv6 ipv6Packet = (IPv6) eth.getPayload();
        if (ipv6Packet.getNextHeader() == IPv6.PROTOCOL_ICMP6) {
            ICMP6 icmp6 = (ICMP6) ipv6Packet.getPayload();
            if (icmp6.getIcmpType() == ICMP6.NEIGHBOR_ADVERTISEMENT) {
                return true;
            }
        }
    }
    return false;
}
 
Example 5
Source File: Dhcp6DirectPacketClassifier.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public boolean match(PacketContext packet) {

    Ethernet eth = packet.inPacket().parsed();

    if (eth.getEtherType() == Ethernet.TYPE_IPV6) {
        IPv6 ipv6Packet = (IPv6) eth.getPayload();

        if (ipv6Packet.getNextHeader() == IPv6.PROTOCOL_UDP) {
            UDP udpPacket = (UDP) ipv6Packet.getPayload();
            //Directly connected host
            if (udpPacket.getDestinationPort() == UDP.DHCP_V6_SERVER_PORT &&
                    udpPacket.getSourcePort() == UDP.DHCP_V6_CLIENT_PORT) {
                DHCP6 dhcp6 = (DHCP6) udpPacket.getPayload();
                if (dhcp6.getMsgType() == DHCP6.MsgType.SOLICIT.value()) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example 6
Source File: NSPacketClassifier.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public boolean match(PacketContext packet) {

    Ethernet eth = packet.inPacket().parsed();

    if (eth.getEtherType() == Ethernet.TYPE_IPV6) {
        IPv6 ipv6Packet = (IPv6) eth.getPayload();
        if (ipv6Packet.getNextHeader() == IPv6.PROTOCOL_ICMP6) {
            ICMP6 icmp6 = (ICMP6) ipv6Packet.getPayload();
            if (icmp6.getIcmpType() == ICMP6.NEIGHBOR_SOLICITATION) {
                return true;
            }
        }
    }
    return false;
}
 
Example 7
Source File: Ofdpa2Pipeline.java    From onos with Apache License 2.0 5 votes vote down vote up
private boolean isSupportedEthTypeObjective(ForwardingObjective fwd) {
    TrafficSelector selector = fwd.selector();
    EthTypeCriterion ethType = (EthTypeCriterion) selector
            .getCriterion(Criterion.Type.ETH_TYPE);
    return !((ethType == null) ||
            ((ethType.ethType().toShort() != Ethernet.TYPE_IPV4) &&
                    (ethType.ethType().toShort() != Ethernet.MPLS_UNICAST)) &&
                    (ethType.ethType().toShort() != Ethernet.TYPE_IPV6));
}
 
Example 8
Source File: Dhcp6IndirectPacketClassifier.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public boolean match(PacketContext packet) {

    Ethernet eth = packet.inPacket().parsed();

    if (eth.getEtherType() == Ethernet.TYPE_IPV6) {
        IPv6 ipv6Packet = (IPv6) eth.getPayload();

        if (ipv6Packet.getNextHeader() == IPv6.PROTOCOL_UDP) {
            UDP udpPacket = (UDP) ipv6Packet.getPayload();
            //Indirectly connected host
            if (udpPacket.getDestinationPort() == UDP.DHCP_V6_SERVER_PORT &&
                    udpPacket.getSourcePort() == UDP.DHCP_V6_SERVER_PORT &&
                    Arrays.equals(ipv6Packet.getDestinationAddress(),
                            Ip6Address.valueOf("ff02::1:2").toOctets())) {
                DHCP6 relayMessage = (DHCP6) udpPacket.getPayload();
                DHCP6 dhcp6 = (DHCP6) relayMessage.getOptions().stream()
                        .filter(opt -> opt instanceof Dhcp6RelayOption)
                        .map(BasePacket::getPayload)
                        .map(pld -> (DHCP6) pld)
                        .findFirst()
                        .orElse(null);

                if (dhcp6.getMsgType() == DHCP6.MsgType.SOLICIT.value()) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example 9
Source File: DefaultNeighbourMessageContext.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Attempts to create a MessageContext for the given Ethernet frame. If the
 * frame is a valid ARP or NDP request or response, a context will be
 * created.
 *
 * @param eth input Ethernet frame
 * @param inPort in port
 * @param actions actions to take
 * @return MessageContext if the packet was ARP or NDP, otherwise null
 */
public static NeighbourMessageContext createContext(Ethernet eth,
                                                    ConnectPoint inPort,
                                                    NeighbourMessageActions actions) {
    if (eth.getEtherType() == Ethernet.TYPE_ARP) {
        return createArpContext(eth, inPort, actions);
    } else if (eth.getEtherType() == Ethernet.TYPE_IPV6) {
        return createNdpContext(eth, inPort, actions);
    }

    return null;
}
 
Example 10
Source File: DefaultNeighbourMessageContext.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Extracts context information from NDP packets.
 *
 * @param eth input Ethernet frame that is thought to be NDP
 * @param inPort in port
 * @param actions actions to take
 * @return MessageContext object if the packet was a valid NDP packet,
 * otherwise null
 */
private static NeighbourMessageContext createNdpContext(Ethernet eth,
                                                        ConnectPoint inPort,
                                                        NeighbourMessageActions actions) {
    if (eth.getEtherType() != Ethernet.TYPE_IPV6) {
        return null;
    }
    IPv6 ipv6 = (IPv6) eth.getPayload();

    if (ipv6.getNextHeader() != IPv6.PROTOCOL_ICMP6) {
        return null;
    }
    ICMP6 icmpv6 = (ICMP6) ipv6.getPayload();

    IpAddress sender = Ip6Address.valueOf(ipv6.getSourceAddress());
    IpAddress target;

    NeighbourMessageType type;
    if (icmpv6.getIcmpType() == ICMP6.NEIGHBOR_SOLICITATION) {
        type = NeighbourMessageType.REQUEST;
        NeighborSolicitation nsol = (NeighborSolicitation) icmpv6.getPayload();
        target = Ip6Address.valueOf(nsol.getTargetAddress());
    } else if (icmpv6.getIcmpType() == ICMP6.NEIGHBOR_ADVERTISEMENT) {
        type = NeighbourMessageType.REPLY;
        /*
         * sender and target are the same in the reply.
         * We use as target the destination ip.
         */
        target = Ip6Address.valueOf(ipv6.getDestinationAddress());
    } else {
        return null;
    }

    return new DefaultNeighbourMessageContext(actions, eth, inPort,
            NeighbourProtocol.NDP, type, target, sender);
}
 
Example 11
Source File: SoftRouterPipeline.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * SoftRouter has a single specific table - the FIB Table. It emulates
 * LPM matching of dstIP by using higher priority flows for longer prefixes.
 * Flows are forwarded using flow-actions
 *
 * @param fwd The forwarding objective of type simple
 * @return A collection of flow rules meant to be delivered to the flowrule
 *         subsystem. Typically the returned collection has a single flowrule.
 *         May return empty collection in case of failures.
 *
 */
private Collection<FlowRule> processSpecific(ForwardingObjective fwd) {
    log.debug("Processing specific forwarding objective to next:{}", fwd.nextId());
    TrafficSelector selector = fwd.selector();
    EthTypeCriterion ethType =
            (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
    // XXX currently supporting only the L3 unicast table
    if (ethType == null || (ethType.ethType().toShort() != TYPE_IPV4
            && ethType.ethType().toShort() != Ethernet.TYPE_IPV6)) {
        fail(fwd, ObjectiveError.UNSUPPORTED);
        return Collections.emptySet();
    }
    //We build the selector according the eth type.
    IpPrefix ipPrefix;
    TrafficSelector.Builder filteredSelector;
    if (ethType.ethType().toShort() == TYPE_IPV4) {
        ipPrefix = ((IPCriterion)
                selector.getCriterion(Criterion.Type.IPV4_DST)).ip();

        filteredSelector = DefaultTrafficSelector.builder()
                .matchEthType(TYPE_IPV4);
    } else {
        ipPrefix = ((IPCriterion)
                selector.getCriterion(Criterion.Type.IPV6_DST)).ip();

        filteredSelector = DefaultTrafficSelector.builder()
                .matchEthType(Ethernet.TYPE_IPV6);
    }
    // If the prefix is different from the default via.
    if (ipPrefix.prefixLength() != 0) {
        if (ethType.ethType().toShort() == TYPE_IPV4) {
            filteredSelector.matchIPDst(ipPrefix);
        } else {
            filteredSelector.matchIPv6Dst(ipPrefix);
        }
    }

    TrafficTreatment tt = null;
    if (fwd.nextId() != null) {
        NextGroup next = flowObjectiveStore.getNextGroup(fwd.nextId());
        if (next == null) {
            log.error("next-id {} does not exist in store", fwd.nextId());
            return Collections.emptySet();
        }
        tt = appKryo.deserialize(next.data());
        if (tt == null)  {
            log.error("Error in deserializing next-id {}", fwd.nextId());
            return Collections.emptySet();
        }
    }

    FlowRule.Builder ruleBuilder = DefaultFlowRule.builder()
            .fromApp(fwd.appId())
            .withPriority(fwd.priority())
            .forDevice(deviceId)
            .withSelector(filteredSelector.build());

    if (tt != null) {
        ruleBuilder.withTreatment(tt);
    }

    if (fwd.permanent()) {
        ruleBuilder.makePermanent();
    } else {
        ruleBuilder.makeTemporary(fwd.timeout());
    }

    ruleBuilder.forTable(FIB_TABLE);
    return Collections.singletonList(ruleBuilder.build());
}
 
Example 12
Source File: PacketStatistics.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public void process(PacketContext context) {
    InboundPacket pkt = context.inPacket();
    Ethernet ethPkt = pkt.parsed();

    //Indicates whether this is an ARP Packet
    if (ethPkt.getEtherType() == Ethernet.TYPE_ARP) {
        arpCounter.inc();

    } else if (ethPkt.getEtherType() == Ethernet.TYPE_LLDP) {
        lldpCounter.inc();

    } else if (ethPkt.getEtherType() == Ethernet.TYPE_VLAN) {
        vlanCounter.inc();

    } else if (ethPkt.getEtherType() == Ethernet.TYPE_BSN) {
        bsnCounter.inc();

    } else if (ethPkt.getEtherType() == Ethernet.TYPE_RARP) {
        rarpCounter.inc();

    } else if (ethPkt.getEtherType() == Ethernet.MPLS_UNICAST
            || ethPkt.getEtherType() == Ethernet.MPLS_MULTICAST) {
        mplsCounter.inc();

    } else if (ethPkt.getEtherType() == Ethernet.TYPE_IPV4) {
        IPv4 ipv4Packet = (IPv4) ethPkt.getPayload();
        //Indicates whether this is a TCP Packet
        if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_TCP) {
            tcpCounter.inc();

        } else if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_ICMP) {
            icmpCounter.inc();

        } else if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_IGMP) {
            igmpCounter.inc();

        } else if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_PIM) {
            pimCounter.inc();

        } else if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_UDP) {
            UDP udpPacket = (UDP) ipv4Packet.getPayload();
                //Indicates whether this packet is a DHCP Packet
                if (udpPacket.getSourcePort() == UDP.DHCP_CLIENT_PORT
                        || udpPacket.getSourcePort() == UDP.DHCP_SERVER_PORT) {
                    dhcpCounter.inc();
                }
            }
    } else if (ethPkt.getEtherType() == Ethernet.TYPE_IPV6) {
           IPv6 ipv6Pkt = (IPv6) ethPkt.getPayload();
           if (ipv6Pkt.getNextHeader() == IPv6.PROTOCOL_ICMP6) {
               icmp6Counter.inc();
               ICMP6 icmpv6 = (ICMP6) ipv6Pkt.getPayload();
               if (icmpv6.getIcmpType() == ICMP6.NEIGHBOR_SOLICITATION) {
                  nbrSolicitCounter.inc();
               } else if (icmpv6.getIcmpType() == ICMP6.NEIGHBOR_ADVERTISEMENT) {
                  nbrAdvertCounter.inc();
               }
           }
    } else {
            log.debug("Packet is unknown.");
            unknownCounter.inc();
    }
}
 
Example 13
Source File: McastForwarding.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Process incoming packets.
 *
 * @param context packet processing context
 */
@Override
public void process(PacketContext context) {
    // Stop processing if the packet has been handled, since we
    // can't do any more to it.
    if (context.isHandled()) {
        return;
    }

    InboundPacket pkt = context.inPacket();
    Ethernet ethPkt = pkt.parsed();

    if (ethPkt == null) {
        return;
    }

    if (ethPkt.getEtherType() != Ethernet.TYPE_IPV4 &&
            ethPkt.getEtherType() != Ethernet.TYPE_IPV6) {
        return;
    }

    if (ethPkt.getEtherType() == Ethernet.TYPE_IPV6) {
        // Ignore ipv6 at the moment.
        return;
    }

    IPv4 ip = (IPv4) ethPkt.getPayload();
    IpAddress saddr = Ip4Address.valueOf(ip.getSourceAddress());
    IpAddress gaddr = IpAddress.valueOf(ip.getDestinationAddress());

    log.debug("Packet ({}, {}) has been punted\n" +
                    "\tingress port: {}\n",
            saddr.toString(),
            gaddr.toString(),
            context.inPacket().receivedFrom().toString());

    // Don't allow PIM/IGMP packets to be handled here.
    byte proto = ip.getProtocol();
    if (proto == IPv4.PROTOCOL_PIM || proto == IPv4.PROTOCOL_IGMP) {
        return;
    }

    IpPrefix spfx = IpPrefix.valueOf(saddr, 32);
    IpPrefix gpfx = IpPrefix.valueOf(gaddr, 32);

    // TODO do we want to add a type for Mcast?
    McastRoute mRoute = new McastRoute(saddr, gaddr, McastRoute.Type.STATIC);

    ConnectPoint ingress = mcastRouteManager.fetchSource(mRoute);

    // An ingress port already exists. Log error.
    if (ingress != null) {
        log.error(McastForwarding.class.getSimpleName() + " received packet which already has a route.");
        return;
    } else {
        //add ingress port
        mcastRouteManager.addSource(mRoute, pkt.receivedFrom());
    }

    ArrayList<ConnectPoint> egressList = (ArrayList<ConnectPoint>) mcastRouteManager.fetchSinks(mRoute);
    //If there are no egress ports set return, otherwise forward the packets to their expected port.
    if (egressList.isEmpty()) {
        return;
    }

    // Send the pack out each of the egress devices & port
    forwardPacketToDst(context, egressList);
}
 
Example 14
Source File: SegmentRoutingManager.java    From onos with Apache License 2.0 4 votes vote down vote up
private void processPacketInternal(PacketContext context) {
    if (context.isHandled()) {
        return;
    }

    InboundPacket pkt = context.inPacket();
    Ethernet ethernet = pkt.parsed();

    if (ethernet == null) {
        return;
    }

    log.trace("Rcvd pktin from {}: {}", context.inPacket().receivedFrom(),
              ethernet);
    if (ethernet.getEtherType() == TYPE_ARP) {
        log.warn("Received unexpected ARP packet on {}",
                 context.inPacket().receivedFrom());
        log.trace("{}", ethernet);
        return;
    } else if (ethernet.getEtherType() == Ethernet.TYPE_IPV4) {
        IPv4 ipv4Packet = (IPv4) ethernet.getPayload();
        //ipHandler.addToPacketBuffer(ipv4Packet);
        if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_ICMP) {
            icmpHandler.processIcmp(ethernet, pkt.receivedFrom());
        } else {
            // NOTE: We don't support IP learning at this moment so this
            //       is not necessary. Also it causes duplication of DHCP packets.
            // ipHandler.processPacketIn(ipv4Packet, pkt.receivedFrom());
        }
    } else if (ethernet.getEtherType() == Ethernet.TYPE_IPV6) {
        IPv6 ipv6Packet = (IPv6) ethernet.getPayload();
        //ipHandler.addToPacketBuffer(ipv6Packet);
        // We deal with the packet only if the packet is a ICMP6 ECHO/REPLY
        if (ipv6Packet.getNextHeader() == IPv6.PROTOCOL_ICMP6) {
            ICMP6 icmp6Packet = (ICMP6) ipv6Packet.getPayload();
            if (icmp6Packet.getIcmpType() == ICMP6.ECHO_REQUEST ||
                    icmp6Packet.getIcmpType() == ICMP6.ECHO_REPLY) {
                icmpHandler.processIcmpv6(ethernet, pkt.receivedFrom());
            } else {
                log.trace("Received ICMPv6 0x{} - not handled",
                        Integer.toHexString(icmp6Packet.getIcmpType() & 0xff));
            }
        } else {
           // NOTE: We don't support IP learning at this moment so this
           //       is not necessary. Also it causes duplication of DHCPv6 packets.
           // ipHandler.processPacketIn(ipv6Packet, pkt.receivedFrom());
        }
    }
}
 
Example 15
Source File: ReactiveForwarding.java    From onos with Apache License 2.0 4 votes vote down vote up
private boolean isIpv6Multicast(Ethernet eth) {
    return eth.getEtherType() == Ethernet.TYPE_IPV6 && eth.isMulticast();
}
 
Example 16
Source File: OfdpaPipelineUtility.java    From onos with Apache License 2.0 2 votes vote down vote up
/**
 * Returns true iff the given selector matches on ethtype==ipv6, indicating
 * that the selector is trying to match on ipv6 traffic.
 *
 * @param selector the given match
 * @return true iff ethtype==ipv6; false otherwise
 */
static boolean isIpv6(TrafficSelector selector) {
    EthTypeCriterion ethTypeCriterion = (EthTypeCriterion) selector.getCriterion(ETH_TYPE);
    return ethTypeCriterion != null && ethTypeCriterion.ethType().toShort() == Ethernet.TYPE_IPV6;
}