Search in sources :

Example 86 with Ethernet

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

the class DefaultNeighbourMessageActions method forward.

@Override
public void forward(NeighbourMessageContext context, Interface outIntf) {
    Ethernet packetOut = context.packet().duplicate();
    if (outIntf.vlan().equals(VlanId.NONE)) {
        // The egress interface has no VLAN Id. Send out an untagged
        // packet
        packetOut.setVlanID(Ethernet.VLAN_UNTAGGED);
    } else {
        // The egress interface has a VLAN set. Send out a tagged packet
        packetOut.setVlanID(outIntf.vlan().toShort());
    }
    sendTo(packetOut, outIntf.connectPoint());
}
Also used : Ethernet(org.onlab.packet.Ethernet)

Example 87 with Ethernet

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

the class NeighbourResolutionManager method handlePacket.

private void handlePacket(PacketContext context) {
    InboundPacket pkt = context.inPacket();
    Ethernet ethPkt = pkt.parsed();
    NeighbourMessageContext msgContext = DefaultNeighbourMessageContext.createContext(ethPkt, pkt.receivedFrom(), actions);
    if (msgContext == null) {
        return;
    }
    if (handleMessage(msgContext)) {
        context.block();
    }
}
Also used : NeighbourMessageContext(org.onosproject.net.neighbour.NeighbourMessageContext) InboundPacket(org.onosproject.net.packet.InboundPacket) Ethernet(org.onlab.packet.Ethernet)

Example 88 with Ethernet

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

the class NeighborSolicitation method buildNdpSolicit.

/**
 * Builds a NDP solicitation using the supplied parameters.
 *
 * @param targetIp the target ip
 * @param sourceIp the source ip
 * @param destinationIp the destination ip
 * @param sourceMac the source mac address
 * @param destinationMac the destination mac address
 * @param vlan the vlan id
 * @return the ethernet packet containing the ndp solicitation
 */
public static Ethernet buildNdpSolicit(Ip6Address targetIp, Ip6Address sourceIp, Ip6Address destinationIp, MacAddress sourceMac, MacAddress destinationMac, VlanId vlan) {
    checkNotNull(targetIp, "Target IP address cannot be null");
    checkNotNull(sourceIp, "Source IP address cannot be null");
    checkNotNull(destinationIp, "Destination IP address cannot be null");
    checkNotNull(sourceMac, "Source MAC address cannot be null");
    checkNotNull(destinationMac, "Destination MAC address cannot be null");
    checkNotNull(vlan, "Vlan cannot be null");
    // Here we craft the Ethernet packet.
    Ethernet ethernet = new Ethernet();
    ethernet.setEtherType(Ethernet.TYPE_IPV6).setDestinationMACAddress(destinationMac).setSourceMACAddress(sourceMac);
    ethernet.setVlanID(vlan.id());
    // IPv6 packet is created.
    IPv6 ipv6 = new IPv6();
    ipv6.setSourceAddress(sourceIp.toOctets());
    ipv6.setDestinationAddress(destinationIp.toOctets());
    ipv6.setHopLimit(NDP_HOP_LIMIT);
    // Create the ICMPv6 packet.
    ICMP6 icmp6 = new ICMP6();
    icmp6.setIcmpType(ICMP6.NEIGHBOR_SOLICITATION);
    icmp6.setIcmpCode(RESERVED_CODE);
    // Create the Neighbor Solicitation packet.
    NeighborSolicitation ns = new NeighborSolicitation();
    ns.setTargetAddress(targetIp.toOctets());
    // DAD packets should not contain SRC_LL_ADDR option
    if (!Arrays.equals(sourceIp.toOctets(), Ip6Address.ZERO.toOctets())) {
        ns.addOption(NeighborDiscoveryOptions.TYPE_SOURCE_LL_ADDRESS, sourceMac.toBytes());
    }
    // Set the payloads
    icmp6.setPayload(ns);
    ipv6.setPayload(icmp6);
    ethernet.setPayload(ipv6);
    return ethernet;
}
Also used : IPv6(org.onlab.packet.IPv6) Ethernet(org.onlab.packet.Ethernet) ICMP6(org.onlab.packet.ICMP6)

Example 89 with Ethernet

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

the class Dhcp6IndirectPacketClassifier method match.

@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;
}
Also used : UDP(org.onlab.packet.UDP) IPv6(org.onlab.packet.IPv6) BasePacket(org.onlab.packet.BasePacket) Ethernet(org.onlab.packet.Ethernet) Ip6Address(org.onlab.packet.Ip6Address) DHCP6(org.onlab.packet.DHCP6) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) PacketContext(org.onosproject.net.packet.PacketContext) PacketInClassifier(org.onosproject.net.packet.PacketInClassifier) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) UDP(org.onlab.packet.UDP) Dhcp6RelayOption(org.onlab.packet.dhcp.Dhcp6RelayOption) IPv6(org.onlab.packet.IPv6) Ethernet(org.onlab.packet.Ethernet) DHCP6(org.onlab.packet.DHCP6) BasePacket(org.onlab.packet.BasePacket) Dhcp6RelayOption(org.onlab.packet.dhcp.Dhcp6RelayOption)

Example 90 with Ethernet

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

the class HostMonitor method sendProbe.

public void sendProbe(ConnectPoint connectPoint, IpAddress targetIp, IpAddress sourceIp, MacAddress sourceMac, VlanId vlan) {
    log.debug("Sending probe for target:{} out of intf:{} vlan:{}", targetIp, connectPoint, vlan);
    Ethernet probePacket;
    if (targetIp.isIp4()) {
        // IPv4: Use ARP
        probePacket = buildArpRequest(targetIp, sourceIp, sourceMac, vlan);
    } else {
        // IPv6: Use Neighbor Discovery. According to the NDP protocol,
        // we should use the solicitation node address as IPv6 destination
        // and the multicast mac address as Ethernet destination.
        byte[] destIp = IPv6.getSolicitNodeAddress(targetIp.toOctets());
        probePacket = NeighborSolicitation.buildNdpSolicit(targetIp.getIp6Address(), sourceIp.getIp6Address(), Ip6Address.valueOf(destIp), sourceMac, MacAddress.valueOf(IPv6.getMCastMacAddress(destIp)), vlan);
    }
    if (probePacket == null) {
        log.warn("Not able to build the probe packet");
        return;
    }
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(connectPoint.port()).build();
    OutboundPacket outboundPacket = new DefaultOutboundPacket(connectPoint.deviceId(), treatment, ByteBuffer.wrap(probePacket.serialize()));
    packetService.emit(outboundPacket);
}
Also used : Ethernet(org.onlab.packet.Ethernet) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket)

Aggregations

Ethernet (org.onlab.packet.Ethernet)187 Test (org.junit.Test)91 ConnectPoint (org.onosproject.net.ConnectPoint)46 IPv4 (org.onlab.packet.IPv4)42 IPv6 (org.onlab.packet.IPv6)41 UDP (org.onlab.packet.UDP)38 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)33 MacAddress (org.onlab.packet.MacAddress)30 DefaultOutboundPacket (org.onosproject.net.packet.DefaultOutboundPacket)30 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)29 IpAddress (org.onlab.packet.IpAddress)28 OutboundPacket (org.onosproject.net.packet.OutboundPacket)26 DeviceId (org.onosproject.net.DeviceId)25 ByteBuffer (java.nio.ByteBuffer)24 DHCP (org.onlab.packet.DHCP)24 DHCP6 (org.onlab.packet.DHCP6)24 Interface (org.onosproject.net.intf.Interface)22 DeserializationException (org.onlab.packet.DeserializationException)20 ICMP6 (org.onlab.packet.ICMP6)20 InboundPacket (org.onosproject.net.packet.InboundPacket)20