Search in sources :

Example 1 with NeighbourMessageType

use of org.onosproject.net.neighbour.NeighbourMessageType in project onos by opennetworkinglab.

the class DefaultNeighbourMessageContext method createNdpContext.

/**
 * 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);
}
Also used : IPv6(org.onlab.packet.IPv6) NeighborSolicitation(org.onlab.packet.ndp.NeighborSolicitation) IpAddress(org.onlab.packet.IpAddress) NeighbourMessageType(org.onosproject.net.neighbour.NeighbourMessageType) ICMP6(org.onlab.packet.ICMP6)

Example 2 with NeighbourMessageType

use of org.onosproject.net.neighbour.NeighbourMessageType in project onos by opennetworkinglab.

the class DefaultNeighbourMessageContext method createArpContext.

/**
 * Extracts context information from ARP packets.
 *
 * @param eth input Ethernet frame that is thought to be ARP
 * @param inPort in port
 * @param actions actions to take
 * @return MessageContext object if the packet was a valid ARP packet,
 * otherwise null
 */
private static NeighbourMessageContext createArpContext(Ethernet eth, ConnectPoint inPort, NeighbourMessageActions actions) {
    if (eth.getEtherType() != Ethernet.TYPE_ARP) {
        return null;
    }
    ARP arp = (ARP) eth.getPayload();
    IpAddress target = Ip4Address.valueOf(arp.getTargetProtocolAddress());
    IpAddress sender = Ip4Address.valueOf(arp.getSenderProtocolAddress());
    NeighbourMessageType type;
    if (arp.getOpCode() == ARP.OP_REQUEST) {
        type = NeighbourMessageType.REQUEST;
    } else if (arp.getOpCode() == ARP.OP_REPLY) {
        type = NeighbourMessageType.REPLY;
    } else {
        return null;
    }
    return new DefaultNeighbourMessageContext(actions, eth, inPort, NeighbourProtocol.ARP, type, target, sender);
}
Also used : IpAddress(org.onlab.packet.IpAddress) NeighbourMessageType(org.onosproject.net.neighbour.NeighbourMessageType) ARP(org.onlab.packet.ARP)

Aggregations

IpAddress (org.onlab.packet.IpAddress)2 NeighbourMessageType (org.onosproject.net.neighbour.NeighbourMessageType)2 ARP (org.onlab.packet.ARP)1 ICMP6 (org.onlab.packet.ICMP6)1 IPv6 (org.onlab.packet.IPv6)1 NeighborSolicitation (org.onlab.packet.ndp.NeighborSolicitation)1