Search in sources :

Example 56 with Ethernet

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

the class DefaultNeighbourMessageActions method buildNdpReply.

/**
 * Builds an NDP reply based on a request.
 *
 * @param srcIp   the IP address to use as the reply source
 * @param srcMac  the MAC address to use as the reply source
 * @param request the Neighbor Solicitation request we got
 * @param isRouter true if this reply is sent on behalf of a router
 * @return an Ethernet frame containing the Neighbor Advertisement reply
 */
private Ethernet buildNdpReply(Ip6Address srcIp, MacAddress srcMac, Ethernet request, boolean isRouter) {
    Ethernet eth = new Ethernet();
    eth.setDestinationMACAddress(request.getSourceMAC());
    eth.setSourceMACAddress(srcMac);
    eth.setEtherType(Ethernet.TYPE_IPV6);
    eth.setVlanID(request.getVlanID());
    IPv6 requestIp = (IPv6) request.getPayload();
    IPv6 ipv6 = new IPv6();
    ipv6.setSourceAddress(srcIp.toOctets());
    ipv6.setDestinationAddress(requestIp.getSourceAddress());
    ipv6.setHopLimit((byte) 255);
    ICMP6 icmp6 = new ICMP6();
    icmp6.setIcmpType(ICMP6.NEIGHBOR_ADVERTISEMENT);
    icmp6.setIcmpCode((byte) 0);
    NeighborAdvertisement nadv = new NeighborAdvertisement();
    nadv.setTargetAddress(srcIp.toOctets());
    nadv.setSolicitedFlag((byte) 1);
    nadv.setOverrideFlag((byte) 1);
    if (isRouter) {
        nadv.setRouterFlag((byte) 1);
    }
    nadv.addOption(NeighborDiscoveryOptions.TYPE_TARGET_LL_ADDRESS, srcMac.toBytes());
    icmp6.setPayload(nadv);
    ipv6.setPayload(icmp6);
    eth.setPayload(ipv6);
    return eth;
}
Also used : IPv6(org.onlab.packet.IPv6) NeighborAdvertisement(org.onlab.packet.ndp.NeighborAdvertisement) Ethernet(org.onlab.packet.Ethernet) ICMP6(org.onlab.packet.ICMP6)

Example 57 with Ethernet

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

the class IcmpHandler method sendIcmpResponse.

private void sendIcmpResponse(Ethernet icmpRequest, ConnectPoint outport) {
    Ethernet icmpReplyEth = new Ethernet();
    IPv4 icmpRequestIpv4 = (IPv4) icmpRequest.getPayload();
    IPv4 icmpReplyIpv4 = new IPv4();
    int destAddress = icmpRequestIpv4.getDestinationAddress();
    icmpReplyIpv4.setDestinationAddress(icmpRequestIpv4.getSourceAddress());
    icmpReplyIpv4.setSourceAddress(destAddress);
    icmpReplyIpv4.setTtl((byte) 64);
    icmpReplyIpv4.setChecksum((short) 0);
    ICMP icmpReply = new ICMP();
    icmpReply.setPayload(((ICMP) icmpRequestIpv4.getPayload()).getPayload());
    icmpReply.setIcmpType(ICMP.TYPE_ECHO_REPLY);
    icmpReply.setIcmpCode(ICMP.CODE_ECHO_REPLY);
    icmpReply.setChecksum((short) 0);
    icmpReplyIpv4.setPayload(icmpReply);
    icmpReplyEth.setPayload(icmpReplyIpv4);
    icmpReplyEth.setEtherType(Ethernet.TYPE_IPV4);
    icmpReplyEth.setDestinationMACAddress(icmpRequest.getSourceMACAddress());
    icmpReplyEth.setSourceMACAddress(icmpRequest.getDestinationMACAddress());
    icmpReplyEth.setVlanID(icmpRequest.getVlanID());
    sendPacketOut(outport, icmpReplyEth);
}
Also used : Ethernet(org.onlab.packet.Ethernet) IPv4(org.onlab.packet.IPv4) ConnectPoint(org.onosproject.net.ConnectPoint) ICMP(org.onlab.packet.ICMP)

Example 58 with Ethernet

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

the class IcmpHandler method processPacketIn.

private void processPacketIn(InboundPacket pkt) {
    boolean ipMatches = false;
    Ethernet ethernet = pkt.parsed();
    IPv4 ipv4 = (IPv4) ethernet.getPayload();
    ConnectPoint connectPoint = pkt.receivedFrom();
    IpAddress destIpAddress = IpAddress.valueOf(ipv4.getDestinationAddress());
    Interface targetInterface = interfaceService.getMatchingInterface(destIpAddress);
    if (targetInterface == null) {
        log.trace("No matching interface for {}", destIpAddress);
        return;
    }
    for (InterfaceIpAddress interfaceIpAddress : targetInterface.ipAddressesList()) {
        if (interfaceIpAddress.ipAddress().equals(destIpAddress)) {
            ipMatches = true;
            break;
        }
    }
    if (((ICMP) ipv4.getPayload()).getIcmpType() == ICMP.TYPE_ECHO_REQUEST && ipMatches) {
        sendIcmpResponse(ethernet, connectPoint);
    }
}
Also used : Ethernet(org.onlab.packet.Ethernet) IPv4(org.onlab.packet.IPv4) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) IpAddress(org.onlab.packet.IpAddress) ConnectPoint(org.onosproject.net.ConnectPoint) Interface(org.onosproject.net.intf.Interface) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) ICMP(org.onlab.packet.ICMP)

Example 59 with Ethernet

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

the class OpenstackNetworkingUtil method buildGratuitousArpPacket.

/**
 * Returns GARP packet with supplied floating ip and instance port information.
 *
 * @param floatingIP floating ip
 * @param instancePort instance port
 * @param vlanId vlan id
 * @return GARP packet
 */
private static Ethernet buildGratuitousArpPacket(NetFloatingIP floatingIP, InstancePort instancePort, VlanId vlanId) {
    Ethernet ethernet = new Ethernet();
    ethernet.setDestinationMACAddress(MacAddress.BROADCAST);
    ethernet.setSourceMACAddress(instancePort.macAddress());
    ethernet.setEtherType(Ethernet.TYPE_ARP);
    ethernet.setVlanID(vlanId.id());
    ARP arp = new ARP();
    arp.setOpCode(ARP.OP_REPLY);
    arp.setProtocolType(ARP.PROTO_TYPE_IP);
    arp.setHardwareType(ARP.HW_TYPE_ETHERNET);
    arp.setProtocolAddressLength((byte) Ip4Address.BYTE_LENGTH);
    arp.setHardwareAddressLength((byte) Ethernet.DATALAYER_ADDRESS_LENGTH);
    arp.setSenderHardwareAddress(instancePort.macAddress().toBytes());
    arp.setTargetHardwareAddress(MacAddress.BROADCAST.toBytes());
    arp.setSenderProtocolAddress(valueOf(floatingIP.getFloatingIpAddress()).toInt());
    arp.setTargetProtocolAddress(valueOf(floatingIP.getFloatingIpAddress()).toInt());
    ethernet.setPayload(arp);
    return ethernet;
}
Also used : Ethernet(org.onlab.packet.Ethernet) ARP(org.onlab.packet.ARP)

Example 60 with Ethernet

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

the class OpenstackSwitchingArpHandlerTest method testRequest.

/**
 * Tests the response to an ARP Request Packet.
 */
@Test
public void testRequest() {
    Ethernet arpRequest = constructArpPacket(ARP.OP_REQUEST);
    sendPacket(arpRequest);
}
Also used : Ethernet(org.onlab.packet.Ethernet) Test(org.junit.Test)

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