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;
}
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);
}
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);
}
}
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;
}
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);
}
Aggregations