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