use of org.onlab.packet.Ethernet in project onos by opennetworkinglab.
the class LinkDiscovery method handleLldp.
/**
* Handles an incoming LLDP packet. Creates link in topology and adds the
* link for staleness tracking.
*
* @param packetContext packet context
* @return true if handled
*/
public boolean handleLldp(PacketContext packetContext) {
Ethernet eth = packetContext.inPacket().parsed();
if (eth == null) {
return false;
}
if (processOnosLldp(packetContext, eth)) {
return true;
}
if (processLldp(packetContext, eth)) {
return true;
}
ONOSLLDP lldp = ONOSLLDP.parseLLDP(eth);
if (lldp == null) {
log.debug("Cannot parse the packet. It seems that it is not the lldp or bsn packet.");
} else {
log.debug("LLDP packet is dropped due to there are no handlers that properly handle this packet: {}", lldp.toString());
}
return false;
}
use of org.onlab.packet.Ethernet in project onos by opennetworkinglab.
the class NetworkConfigLinksProvider method verify.
private boolean verify(PacketContext packetContext) {
Ethernet eth = packetContext.inPacket().parsed();
if (eth == null) {
return false;
}
ONOSLLDP onoslldp = ONOSLLDP.parseONOSLLDP(eth);
if (onoslldp != null) {
if (!isOthercluster(eth.getSourceMAC().toString())) {
return false;
}
if (!ONOSLLDP.verify(onoslldp, context.lldpSecret(), context.maxDiscoveryDelay())) {
log.warn("LLDP Packet failed to validate!");
return false;
}
return true;
}
return false;
}
use of org.onlab.packet.Ethernet in project onos by opennetworkinglab.
the class NetworkConfigLinksProvider method extractLinkKey.
// doesn't validate. Used just to decide if this is expected link.
LinkKey extractLinkKey(PacketContext packetContext) {
Ethernet eth = packetContext.inPacket().parsed();
if (eth == null) {
return null;
}
ONOSLLDP onoslldp = ONOSLLDP.parseONOSLLDP(eth);
if (onoslldp != null) {
PortNumber srcPort = portNumber(onoslldp.getPort());
PortNumber dstPort = packetContext.inPacket().receivedFrom().port();
DeviceId srcDeviceId = DeviceId.deviceId(onoslldp.getDeviceString());
DeviceId dstDeviceId = packetContext.inPacket().receivedFrom().deviceId();
ConnectPoint src = new ConnectPoint(srcDeviceId, srcPort);
ConnectPoint dst = new ConnectPoint(dstDeviceId, dstPort);
return LinkKey.linkKey(src, dst);
}
return null;
}
use of org.onlab.packet.Ethernet in project onos by opennetworkinglab.
the class HostLocationProvider method sendProbe.
private void sendProbe(Host host, IpAddress targetIp) {
Ethernet probePacket = null;
if (targetIp.isIp4()) {
// IPv4: Use ARP
probePacket = buildArpRequest(targetIp, host);
} else {
// IPv6: Use Neighbor Discovery
// TODO need to implement ndp probe
log.info("Triggering probe on device {} ", host);
return;
}
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(host.location().port()).build();
OutboundPacket outboundPacket = new DefaultOutboundPacket(host.location().deviceId(), treatment, ByteBuffer.wrap(probePacket.serialize()));
packetService.emit(outboundPacket);
}
use of org.onlab.packet.Ethernet in project onos by opennetworkinglab.
the class BasicInterpreterImpl method mapInboundPacket.
@Override
public InboundPacket mapInboundPacket(PiPacketOperation packetIn, DeviceId deviceId) throws PiInterpreterException {
// Assuming that the packet is ethernet, which is fine since basic.p4
// can deparse only ethernet packets.
Ethernet ethPkt;
try {
ethPkt = Ethernet.deserializer().deserialize(packetIn.data().asArray(), 0, packetIn.data().size());
} catch (DeserializationException dex) {
throw new PiInterpreterException(dex.getMessage());
}
// Returns the ingress port packet metadata.
Optional<PiPacketMetadata> packetMetadata = packetIn.metadatas().stream().filter(m -> m.id().equals(INGRESS_PORT)).findFirst();
if (packetMetadata.isPresent()) {
ImmutableByteSequence portByteSequence = packetMetadata.get().value();
short s = portByteSequence.asReadOnlyBuffer().getShort();
ConnectPoint receivedFrom = new ConnectPoint(deviceId, PortNumber.portNumber(s));
ByteBuffer rawData = ByteBuffer.wrap(packetIn.data().asArray());
return new DefaultInboundPacket(receivedFrom, ethPkt, rawData);
} else {
throw new PiInterpreterException(format("Missing metadata '%s' in packet-in received from '%s': %s", INGRESS_PORT, deviceId, packetIn));
}
}
Aggregations