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

The following examples show how to use org.onlab.packet.Ethernet#TYPE_IPV4 . 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: OpenstackSwitchingDhcpHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void process(PacketContext context) {
    if (context.isHandled()) {
        return;
    }

    Ethernet ethPacket = context.inPacket().parsed();
    if (ethPacket == null || ethPacket.getEtherType() != Ethernet.TYPE_IPV4) {
        return;
    }
    IPv4 ipv4Packet = (IPv4) ethPacket.getPayload();
    if (ipv4Packet.getProtocol() != IPv4.PROTOCOL_UDP) {
        return;
    }
    UDP udpPacket = (UDP) ipv4Packet.getPayload();
    if (udpPacket.getDestinationPort() != UDP.DHCP_SERVER_PORT ||
            udpPacket.getSourcePort() != UDP.DHCP_CLIENT_PORT) {
        return;
    }

    DHCP dhcpPacket = (DHCP) udpPacket.getPayload();

    eventExecutor.execute(() -> processDhcp(context, dhcpPacket));
}
 
Example 2
Source File: DhcpPacketClassifier.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_IPV4) {
        IPv4 ipv4Packet = (IPv4) eth.getPayload();

        if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_UDP) {
            UDP udpPacket = (UDP) ipv4Packet.getPayload();

            if (udpPacket.getDestinationPort() == UDP.DHCP_SERVER_PORT &&
                    udpPacket.getSourcePort() == UDP.DHCP_CLIENT_PORT) {
                DHCP dhcp = (DHCP) udpPacket.getPayload();
                if (dhcp.getPacketType() == DHCP.MsgType.DHCPDISCOVER) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example 3
Source File: AbstractCorsaPipeline.java    From onos with Apache License 2.0 6 votes vote down vote up
private Collection<FlowRule> processSpecific(ForwardingObjective fwd) {
    log.debug("Processing specific forwarding objective");
    TrafficSelector selector = fwd.selector();
    EthTypeCriterion ethTypeCriterion =
            (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
    VlanIdCriterion vlanIdCriterion =
            (VlanIdCriterion) selector.getCriterion(Criterion.Type.VLAN_VID);
    if (ethTypeCriterion != null) {
        short et = ethTypeCriterion.ethType().toShort();
        if (et == Ethernet.TYPE_IPV4) {
            return processSpecificRoute(fwd);
        } else if (et == Ethernet.TYPE_VLAN) {
            /* The ForwardingObjective must specify VLAN ethtype in order to use the Transit Circuit */
            return processSpecificSwitch(fwd);
        }
    } else if (vlanIdCriterion != null) {
        return processSpecificSwitch(fwd);
    }

    fail(fwd, ObjectiveError.UNSUPPORTED);
    return ImmutableSet.of();
}
 
Example 4
Source File: IcmpPacketClassifier.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_IPV4) {
        IPv4 ipv4Packet = (IPv4) eth.getPayload();

        if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_ICMP) {
            ICMP icmpPacket = (ICMP) ipv4Packet.getPayload();
            if (icmpPacket.getIcmpType() == ICMP.TYPE_ECHO_REQUEST) {
                return true;
            }
        }
    }
    return false;
}
 
Example 5
Source File: K8sSwitchingHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Configures the flow rule which is for using VXLAN/GRE/GENEVE to tag the packet
 * based on the in_port number of a virtual instance.
 * Note that this rule will be inserted in vTag table.
 *
 * @param port kubernetes port object
 * @param install install flag, add the rule if true, remove it otherwise
 */
private void setTunnelTagFlowRules(K8sPort port, short ethType, boolean install) {
    TrafficSelector selector = DefaultTrafficSelector.builder()
            .matchEthType(ethType)
            .matchInPort(port.portNumber())
            .build();

    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder()
            .setTunnelId(getVni(port));

    if (ethType == Ethernet.TYPE_ARP) {
        tBuilder.transition(ARP_TABLE);
    } else if (ethType == Ethernet.TYPE_IPV4) {
        tBuilder.transition(JUMP_TABLE);
    }

    k8sFlowRuleService.setRule(
            appId,
            port.deviceId(),
            selector,
            tBuilder.build(),
            PRIORITY_TUNNEL_TAG_RULE,
            VTAG_TABLE,
            install);
}
 
Example 6
Source File: OpenstackSwitchingHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
private void setDownstreamRuleForFlat(InstancePort instPort,
                                      short ethType, boolean install) {
    TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();

    if (ethType == Ethernet.TYPE_IPV4) {
        sBuilder.matchEthType(Ethernet.TYPE_IPV4)
                .matchIPDst(instPort.ipAddress().toIpPrefix());
    } else if (ethType == Ethernet.TYPE_ARP) {
        sBuilder.matchEthType(Ethernet.TYPE_ARP)
                .matchArpTpa(instPort.ipAddress().getIp4Address());
    }

    TrafficTreatment treatment = DefaultTrafficTreatment.builder()
            .setOutput(instPort.portNumber())
            .build();

    osFlowRuleService.setRule(
            appId,
            instPort.deviceId(),
            sBuilder.build(),
            treatment,
            PRIORITY_FLAT_DOWNSTREAM_RULE,
            FLAT_TABLE,
            install);
}
 
Example 7
Source File: TunnellingConnectivityManager.java    From onos with Apache License 2.0 6 votes vote down vote up
@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;
    }

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

    if (packet == null) {
        return;
    }

    if (packet.getEtherType() == Ethernet.TYPE_IPV4) {
        IPv4 ipv4Packet = (IPv4) packet.getPayload();
        if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_TCP) {
            TCP tcpPacket = (TCP) ipv4Packet.getPayload();

            if (tcpPacket.getDestinationPort() == BGP_PORT ||
                    tcpPacket.getSourcePort() == BGP_PORT) {
                forward(context);
            }
        }
    }
}
 
Example 8
Source File: IcmpHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
@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;
    }

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

    if (packet == null) {
        return;
    }

    if (packet.getEtherType() == Ethernet.TYPE_IPV4) {
        IPv4 ipv4Packet = (IPv4) packet.getPayload();
        if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_ICMP) {
            processPacketIn(context.inPacket());
        }
    }
}
 
Example 9
Source File: VtnManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void process(PacketContext context) {
    InboundPacket pkt = context.inPacket();
    ConnectPoint connectPoint = pkt.receivedFrom();
    DeviceId deviceId = connectPoint.deviceId();
    Ethernet ethPkt = pkt.parsed();
    if (ethPkt == null) {
        return;
    }
    if (ethPkt.getEtherType() == Ethernet.TYPE_ARP) {
        ARP arpPacket = (ARP) ethPkt.getPayload();
        if ((arpPacket.getOpCode() == ARP.OP_REQUEST)) {
            arprequestProcess(arpPacket, deviceId);
        } else if (arpPacket.getOpCode() == ARP.OP_REPLY) {
            arpresponceProcess(arpPacket, deviceId);
        }
    } else if (ethPkt.getEtherType() == Ethernet.TYPE_IPV4) {
        if (ethPkt.getDestinationMAC().isMulticast()) {
            return;
        }
        IPv4 ip = (IPv4) ethPkt.getPayload();
        upStreamPacketProcessor(ip, deviceId);

    } else {
        return;
    }
}
 
Example 10
Source File: AbstractCorsaPipeline.java    From onos with Apache License 2.0 5 votes vote down vote up
private Collection<FlowRule> processVersatile(ForwardingObjective fwd) {
    log.debug("Processing vesatile forwarding objective");
    TrafficSelector selector = fwd.selector();

    EthTypeCriterion ethType =
            (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
    if (ethType == null) {
        log.error("Versatile forwarding objective must include ethType");
        fail(fwd, ObjectiveError.UNKNOWN);
        return ImmutableSet.of();
    }
    Builder rule = DefaultFlowRule.builder()
            .forDevice(deviceId)
            .withSelector(fwd.selector())
            .withTreatment(fwd.treatment())
            .withPriority(fwd.priority())
            .fromApp(fwd.appId())
            .makePermanent();
    if (ethType.ethType().toShort() == Ethernet.TYPE_ARP) {
        return processArpTraffic(fwd, rule);
    } else if (ethType.ethType().toShort() == Ethernet.TYPE_LLDP ||
            ethType.ethType().toShort() == Ethernet.TYPE_BSN) {
        return processLinkDiscovery(fwd, rule);
    } else if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) {
        return processIpTraffic(fwd, rule);
    }
    log.warn("Driver does not support given versatile forwarding objective");
    fail(fwd, ObjectiveError.UNSUPPORTED);
    return ImmutableSet.of();
}
 
Example 11
Source File: PimPacketHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Sanitize and process the packet.
 * TODO: replace ConnectPoint with PIMInterface when PIMInterface has been added.
 *
 * @param ethPkt the packet starting with the Ethernet header.
 * @param pimi the PIM Interface the packet arrived on.
 */
public void processPacket(Ethernet ethPkt, PimInterface pimi) {
    checkNotNull(ethPkt);
    checkNotNull(pimi);

    // Sanitize the ethernet header to ensure it is IPv4.  IPv6 we'll deal with later
    if (ethPkt.getEtherType() != Ethernet.TYPE_IPV4) {
        return;
    }

    // Get the IP header
    IPv4 ip = (IPv4) ethPkt.getPayload();
    if (ip.getProtocol() != IPv4.PROTOCOL_PIM) {
        return;
    }

    // Get the address of our the neighbor that sent this packet to us.
    IpAddress nbraddr = IpAddress.valueOf(ip.getDestinationAddress());
    if (log.isTraceEnabled()) {
        log.trace("Packet {} received on port {}", nbraddr, pimi);
    }

    // Get the PIM header
    PIM pim = (PIM) ip.getPayload();
    checkNotNull(pim);

    // Process the pim packet
    switch (pim.getPimMsgType()) {
        case PIM.TYPE_HELLO:
            pimi.processHello(ethPkt);
            break;
        case PIM.TYPE_JOIN_PRUNE_REQUEST:
            pimi.processJoinPrune(ethPkt);
            log.debug("Received a PIM Join/Prune message");
            break;
        default:
            log.debug("Received unsupported PIM type: {}", pim.getPimMsgType());
            break;
    }
}
 
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: LearningSwitchSolution.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Ensures packet is of required type. Obtain the PortNumber associated with the inPackets DeviceId.
 * If this port has previously been learned (in initMacTable method) build a flow using the packet's
 * out port, treatment, destination, and other properties.  Send the flow to the learned out port.
 * Otherwise, flood packet to all ports if out port is not learned.
 *
 * @param pc the PacketContext object passed through from activate() method
 */
public void actLikeSwitch(PacketContext pc) {

    /*
     * Ensures the type of packet being processed is only of type IPV4 (not LLDP or BDDP).  If it is not, return
     * and do nothing with the packet. actLikeSwitch can only process IPV4 packets.
     */
    Short type = pc.inPacket().parsed().getEtherType();
    if (type != Ethernet.TYPE_IPV4 && type != Ethernet.TYPE_ARP) {
        return;
    }

    /*
     * Learn the destination, source, and output port of the packet using a ConnectPoint and the
     * associated macTable.  If there is a known port associated with the packet's destination MAC Address,
     * the output port will not be null.
     */
    ConnectPoint cp = pc.inPacket().receivedFrom();
    Map<MacAddress, PortNumber> macTable = macTables.get(cp.deviceId());
    MacAddress srcMac = pc.inPacket().parsed().getSourceMAC();
    MacAddress dstMac = pc.inPacket().parsed().getDestinationMAC();
    macTable.put(srcMac, cp.port());
    PortNumber outPort = macTable.get(dstMac);

    /*
     * If port is known, set pc's out port to the packet's learned output port and construct a
     * FlowRule using a source, destination, treatment and other properties. Send the FlowRule
     * to the designated output port.
     */
    if (outPort != null) {
        pc.treatmentBuilder().setOutput(outPort);
        FlowRule fr = DefaultFlowRule.builder()
                .withSelector(DefaultTrafficSelector.builder().matchEthDst(dstMac).build())
                .withTreatment(DefaultTrafficTreatment.builder().setOutput(outPort).build())
                .forDevice(cp.deviceId()).withPriority(PacketPriority.REACTIVE.priorityValue())
                .makeTemporary(60)
                .fromApp(appId).build();

        flowRuleService.applyFlowRules(fr);
        pc.send();
    } else {
    /*
     * else, the output port has not been learned yet.  Flood the packet to all ports using
     * the actLikeHub method
     */
        actLikeHub(pc);
    }
}
 
Example 14
Source File: OpenstackMetadataProxyHandler.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public void process(PacketContext context) {

    if (context.isHandled()) {
        return;
    }

    // FIXME: need to find a way to spawn a new thread to check metadata proxy mode
    if (!useMetadataProxy()) {
        return;
    }

    Ethernet ethPacket = context.inPacket().parsed();
    if (ethPacket == null || ethPacket.getEtherType() != Ethernet.TYPE_IPV4) {
        return;
    }

    IPv4 ipv4Packet = (IPv4) ethPacket.getPayload();
    if (ipv4Packet.getProtocol() != IPv4.PROTOCOL_TCP ||
            !IpAddress.valueOf(ipv4Packet.getDestinationAddress()).
                    equals(IpAddress.valueOf(METADATA_SERVER_IP))) {
        return;
    }

    TCP tcpPacket = (TCP) ipv4Packet.getPayload();
    if (tcpPacket.getDestinationPort() != HTTP_SERVER_PORT) {
        return;
    }

    // (three-way handshaking)
    // reply TCP SYN-ACK packet with receiving TCP SYN packet
    if (tcpPacket.getFlags() == SYN_FLAG) {
        Ethernet ethReply = buildTcpSynAckPacket(ethPacket, ipv4Packet, tcpPacket);
        sendReply(context, ethReply);
        return;
    }

    // (four-way handshaking)
    // reply TCP ACK and TCP FIN-ACK packets with receiving TCP FIN-ACK packet
    if (tcpPacket.getFlags() == FIN_ACK_FLAG) {
        Ethernet ackReply = buildTcpAckPacket(ethPacket, ipv4Packet, tcpPacket);
        sendReply(context, ackReply);
        Ethernet finAckReply = buildTcpFinAckPacket(ethPacket, ipv4Packet, tcpPacket);
        sendReply(context, finAckReply);
        return;
    }

    // normal TCP data transmission
    Data data = (Data) tcpPacket.getPayload();
    byte[] byteData = data.getData();

    if (byteData.length != 0) {
        eventExecutor.execute(() -> {
            processHttpRequest(context, ethPacket, ipv4Packet, tcpPacket, byteData);
        });
    }
}
 
Example 15
Source File: MaoRoutingManager.java    From ONOS_LoadBalance_Routing_Forward with Apache License 2.0 4 votes vote down vote up
@Override
        public void process(PacketContext context) {

            if (context.isHandled()) {
                return;
            }

            Ethernet pkt = context.inPacket().parsed();
            if (pkt.getEtherType() == Ethernet.TYPE_IPV4) {

                HostId srcHostId = HostId.hostId(pkt.getSourceMAC());
                HostId dstHostId = HostId.hostId(pkt.getDestinationMAC());

                Set<Path> paths = getLoadBalancePaths(srcHostId, dstHostId);
                if (paths.isEmpty()) {
                    log.warn("paths is Empty !!! no Path is available");
                    context.block();
                    return;
                }

                IPv4 ipPkt = (IPv4) pkt.getPayload();
                TrafficSelector selector = DefaultTrafficSelector.builder()
                        .matchEthType(Ethernet.TYPE_IPV4)
                        .matchIPSrc(IpPrefix.valueOf(ipPkt.getSourceAddress(), 32))
                        .matchIPDst(IpPrefix.valueOf(ipPkt.getDestinationAddress(), 32))
                        .build();

                boolean isContain;
//                synchronized (intentMap) {
                isContain = intentMap.containsKey(selector.criteria());
//                }
                if (isContain) {
                    context.block();
                    return;
                }


                Path result = paths.iterator().next();
                log.info("\n------ Mao Path Info ------\nSrc:{}, Dst:{}\n{}",
                        IpPrefix.valueOf(ipPkt.getSourceAddress(), 32).toString(),
                        IpPrefix.valueOf(ipPkt.getDestinationAddress(), 32),
                        result.links().toString().replace("Default", "\n"));

                PathIntent pathIntent = PathIntent.builder()
                        .path(result)
                        .appId(appId)
                        .priority(65432)
                        .selector(selector)
                        .treatment(DefaultTrafficTreatment.emptyTreatment())
                        .build();

                intentService.submit(pathIntent);

//                synchronized (intentMap) {
                intentMap.put(selector.criteria(), pathIntent);
//                }

                context.block();
            }
        }
 
Example 16
Source File: PicaPipeline.java    From onos with Apache License 2.0 4 votes vote down vote up
private Collection<FlowRule> processSpecific(ForwardingObjective fwd) {
    log.debug("Processing specific forwarding objective");
    TrafficSelector selector = fwd.selector();
    EthTypeCriterion ethType =
            (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
    if (ethType == null || ethType.ethType().toShort() != Ethernet.TYPE_IPV4) {
        fail(fwd, ObjectiveError.UNSUPPORTED);
        return Collections.emptySet();
    }

    List<FlowRule> ipflows = new ArrayList<FlowRule>();
    for (Filter f: filters) {
        TrafficSelector filteredSelector =
                DefaultTrafficSelector.builder()
                .matchEthType(Ethernet.TYPE_IPV4)
                .matchIPDst(
                            ((IPCriterion)
                                    selector.getCriterion(Criterion.Type.IPV4_DST)).ip())
                .matchEthDst(f.mac())
                .matchVlanId(f.vlanId())
                .build();
        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)
                .withTreatment(tt);
        if (fwd.permanent()) {
            ruleBuilder.makePermanent();
        } else {
            ruleBuilder.makeTemporary(fwd.timeout());
        }
        ruleBuilder.forTable(IP_UNICAST_TABLE);
        ipflows.add(ruleBuilder.build());
    }

    return ipflows;
}
 
Example 17
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 18
Source File: CentecV350Pipeline.java    From onos with Apache License 2.0 4 votes vote down vote up
private Collection<FlowRule> processSpecific(ForwardingObjective fwd) {
    log.debug("Processing specific forwarding objective");
    TrafficSelector selector = fwd.selector();
    EthTypeCriterion ethType =
            (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
    if (ethType == null || ethType.ethType().toShort() != Ethernet.TYPE_IPV4) {
        fail(fwd, ObjectiveError.UNSUPPORTED);
        return Collections.emptySet();
    }

    // Must have metadata as key.
    TrafficSelector filteredSelector =
            DefaultTrafficSelector.builder()
                    .matchEthType(Ethernet.TYPE_IPV4)
                    .matchMetadata(DEFAULT_METADATA)
                    .matchIPDst(
                            ((IPCriterion)
                                    selector.getCriterion(Criterion.Type.IPV4_DST)).ip())
                    .build();

    TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder();

    if (fwd.nextId() != null) {
        NextGroup next = flowObjectiveStore.getNextGroup(fwd.nextId());
        GroupKey key = appKryo.deserialize(next.data());
        Group group = groupService.getGroup(deviceId, key);
        if (group == null) {
            log.warn("The group left!");
            fail(fwd, ObjectiveError.GROUPMISSING);
            return Collections.emptySet();
        }
        tb.group(group.id());
    }

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

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

    ruleBuilder.forTable(ROUTE_TABLE);

    return Collections.singletonList(ruleBuilder.build());

}
 
Example 19
Source File: ReactiveForwarding.java    From onos with Apache License 2.0 4 votes vote down vote up
@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;
    }

    MacAddress macAddress = ethPkt.getSourceMAC();
    ReactiveForwardMetrics macMetrics = null;
    macMetrics = createCounter(macAddress);
    inPacket(macMetrics);

    // Bail if this is deemed to be a control packet.
    if (isControlPacket(ethPkt)) {
        droppedPacket(macMetrics);
        return;
    }

    // Skip IPv6 multicast packet when IPv6 forward is disabled.
    if (!ipv6Forwarding && isIpv6Multicast(ethPkt)) {
        droppedPacket(macMetrics);
        return;
    }

    HostId id = HostId.hostId(ethPkt.getDestinationMAC(), VlanId.vlanId(ethPkt.getVlanID()));

    // Do not process LLDP MAC address in any way.
    if (id.mac().isLldp()) {
        droppedPacket(macMetrics);
        return;
    }

    // Do not process IPv4 multicast packets, let mfwd handle them
    if (ignoreIPv4Multicast && ethPkt.getEtherType() == Ethernet.TYPE_IPV4) {
        if (id.mac().isMulticast()) {
            return;
        }
    }

    // Do we know who this is for? If not, flood and bail.
    Host dst = hostService.getHost(id);
    if (dst == null) {
        flood(context, macMetrics);
        return;
    }

    // Are we on an edge switch that our destination is on? If so,
    // simply forward out to the destination and bail.
    if (pkt.receivedFrom().deviceId().equals(dst.location().deviceId())) {
        if (!context.inPacket().receivedFrom().port().equals(dst.location().port())) {
            installRule(context, dst.location().port(), macMetrics);
        }
        return;
    }

    // Otherwise, get a set of paths that lead from here to the
    // destination edge switch.
    Set<Path> paths =
            topologyService.getPaths(topologyService.currentTopology(),
                                     pkt.receivedFrom().deviceId(),
                                     dst.location().deviceId());
    if (paths.isEmpty()) {
        // If there are no paths, flood and bail.
        flood(context, macMetrics);
        return;
    }

    // Otherwise, pick a path that does not lead back to where we
    // came from; if no such path, flood and bail.
    Path path = pickForwardPathIfPossible(paths, pkt.receivedFrom().port());
    if (path == null) {
        log.warn("Don't know where to go from here {} for {} -> {}",
                 pkt.receivedFrom(), ethPkt.getSourceMAC(), ethPkt.getDestinationMAC());
        flood(context, macMetrics);
        return;
    }

    // Otherwise forward and be done with it.
    installRule(context, path.src().port(), macMetrics);
}
 
Example 20
Source File: OvsOfdpaPipeline.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Handles forwarding rules to the IP Unicast Routing.
 *
 * @param fwd the forwarding objective
 * @return A collection of flow rules, or an empty set
 */
protected Collection<FlowRule> processDoubleTaggedFwd(ForwardingObjective fwd) {
    // inner for UNICAST_ROUTING_TABLE_1, outer for UNICAST_ROUTING_TABLE
    TrafficSelector selector = fwd.selector();
    TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
    TrafficTreatment.Builder innerTtb = DefaultTrafficTreatment.builder();
    TrafficTreatment.Builder outerTtb = DefaultTrafficTreatment.builder();

    EthTypeCriterion ethType =
            (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);

    if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) {
        sBuilder.matchEthType(Ethernet.TYPE_IPV4);
        sBuilder.matchVlanId(VlanId.ANY);
        IpPrefix ipv4Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV4_DST)).ip();
        if (!ipv4Dst.isMulticast() && ipv4Dst.prefixLength() == 32) {
            sBuilder.matchIPDst(ipv4Dst);
            if (fwd.nextId() != null) {
                NextGroup next = getGroupForNextObjective(fwd.nextId());
                if (next != null) {
                    List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data());
                    // we only need the top level group's key to point the flow to it
                    Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst());
                    if (group == null) {
                        log.warn("Group with key:{} for next-id:{} not found in dev:{}",
                                 gkeys.get(0).peekFirst(), fwd.nextId(), deviceId);
                        fail(fwd, ObjectiveError.GROUPMISSING);
                        return Collections.emptySet();
                    }
                    outerTtb.immediate().setVlanId(extractDummyVlanIdFromGroupId(group.id().id()));
                    //ACTSET_OUTPUT in OVS will match output action in write_action() set.
                    outerTtb.deferred().setOutput(extractOutputPortFromGroupId(group.id().id()));
                    outerTtb.transition(EGRESS_VLAN_FLOW_TABLE_IN_INGRESS);
                    innerTtb.deferred().group(group.id());
                    innerTtb.transition(ACL_TABLE);

                    FlowRule.Builder innerRuleBuilder = DefaultFlowRule.builder()
                            .fromApp(fwd.appId())
                            .withPriority(fwd.priority())
                            .forDevice(deviceId)
                            .withSelector(sBuilder.build())
                            .withTreatment(innerTtb.build())
                            .forTable(UNICAST_ROUTING_TABLE_1);
                    if (fwd.permanent()) {
                        innerRuleBuilder.makePermanent();
                    } else {
                        innerRuleBuilder.makeTemporary(fwd.timeout());
                    }
                    Collection<FlowRule> flowRuleCollection = new HashSet<>();
                    flowRuleCollection.add(innerRuleBuilder.build());

                    FlowRule.Builder outerRuleBuilder = DefaultFlowRule.builder()
                            .fromApp(fwd.appId())
                            .withPriority(fwd.priority())
                            .forDevice(deviceId)
                            .withSelector(sBuilder.build())
                            .withTreatment(outerTtb.build())
                            .forTable(UNICAST_ROUTING_TABLE);
                    if (fwd.permanent()) {
                        outerRuleBuilder.makePermanent();
                    } else {
                        outerRuleBuilder.makeTemporary(fwd.timeout());
                    }
                    flowRuleCollection.add(innerRuleBuilder.build());
                    flowRuleCollection.add(outerRuleBuilder.build());
                    return flowRuleCollection;
                } else {
                    log.warn("Cannot find group for nextId:{} in dev:{}. Aborting fwd:{}",
                             fwd.nextId(), deviceId, fwd.id());
                    fail(fwd, ObjectiveError.FLOWINSTALLATIONFAILED);
                    return Collections.emptySet();
                }
            } else {
                log.warn("NextId is not specified in fwd:{}", fwd.id());
                fail(fwd, ObjectiveError.FLOWINSTALLATIONFAILED);
                return Collections.emptySet();
            }
        }
    }
    return Collections.emptySet();
}