use of org.onosproject.net.packet.DefaultOutboundPacket in project onos by opennetworkinglab.
the class OpenstackRoutingSnatHandler method packetOut.
private void packetOut(Ethernet ethPacketIn, DeviceId srcDevice, int patPort, IpAddress externalIp, ExternalPeerRouter externalPeerRouter) {
IPv4 iPacket = (IPv4) ethPacketIn.getPayload();
switch(iPacket.getProtocol()) {
case IPv4.PROTOCOL_TCP:
iPacket.setPayload(buildPacketOutTcp(iPacket, patPort));
break;
case IPv4.PROTOCOL_UDP:
iPacket.setPayload(buildPacketOutUdp(iPacket, patPort));
break;
default:
log.trace("Temporally, this method can process UDP and TCP protocol.");
return;
}
iPacket.setSourceAddress(externalIp.toString());
iPacket.resetChecksum();
iPacket.setParent(ethPacketIn);
ethPacketIn.setSourceMACAddress(DEFAULT_GATEWAY_MAC);
ethPacketIn.setDestinationMACAddress(externalPeerRouter.macAddress());
ethPacketIn.setPayload(iPacket);
if (!externalPeerRouter.vlanId().equals(VlanId.NONE)) {
ethPacketIn.setVlanID(externalPeerRouter.vlanId().toShort());
}
ethPacketIn.resetChecksum();
OpenstackNode srcNode = osNodeService.node(srcDevice);
if (srcNode == null) {
final String error = String.format("Cannot find openstack node for %s", srcDevice);
throw new IllegalStateException(error);
}
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
packetService.emit(new DefaultOutboundPacket(srcDevice, tBuilder.setOutput(srcNode.uplinkPortNum()).build(), ByteBuffer.wrap(ethPacketIn.serialize())));
}
use of org.onosproject.net.packet.DefaultOutboundPacket in project onos by opennetworkinglab.
the class P4RuntimePacketProvider method handleP4RuntimeEvent.
private void handleP4RuntimeEvent(P4RuntimeEvent event) {
// FIXME we need the device ID into p4RuntimeEvnetSubject to check for mastsership
if (!(event.subject() instanceof P4RuntimePacketIn) || event.type() != P4RuntimeEvent.Type.PACKET_IN) {
log.debug("Unrecognized event type {}, discarding", event.type());
// Not a packet-in event, ignore it.
return;
}
P4RuntimePacketIn eventSubject = (P4RuntimePacketIn) event.subject();
DeviceId deviceId = eventSubject.deviceId();
Device device = deviceService.getDevice(eventSubject.deviceId());
if (device == null) {
log.warn("Unable to process packet-in from {}, device is null in the core", deviceId);
return;
}
if (!device.is(PiPipelineInterpreter.class)) {
log.warn("Unable to process packet-in from {}, device has no PiPipelineInterpreter behaviour", deviceId);
return;
}
PiPacketOperation operation = eventSubject.packetOperation();
InboundPacket inPkt;
try {
inPkt = device.as(PiPipelineInterpreter.class).mapInboundPacket(operation, deviceId);
} catch (PiPipelineInterpreter.PiInterpreterException e) {
log.warn("Unable to interpret inbound packet from {}: {}", deviceId, e.getMessage());
return;
}
if (log.isTraceEnabled()) {
final EthType.EtherType etherType = getEtherType(inPkt.unparsed());
log.trace("Received PACKET-IN <<< device={} ingress_port={} eth_type={}", inPkt.receivedFrom().deviceId(), inPkt.receivedFrom().port(), etherType.ethType().toString());
}
if (inPkt == null) {
log.debug("Received null inbound packet. Ignoring.");
return;
}
OutboundPacket outPkt = new DefaultOutboundPacket(eventSubject.deviceId(), null, operation.data().asReadOnlyBuffer());
PacketContext pktCtx = new P4RuntimePacketContext(System.currentTimeMillis(), inPkt, outPkt, false);
// Pushing the packet context up for processing.
providerService.processPacket(pktCtx);
}
use of org.onosproject.net.packet.DefaultOutboundPacket in project onos by opennetworkinglab.
the class LinkDiscovery method createOutBoundBddp.
/**
* Creates packet_out BDDP for specified output port.
*
* @param portNumber the port
* @param portDesc the port description
* @return Packet_out message with LLDP data
*/
private OutboundPacket createOutBoundBddp(Long portNumber, String portDesc) {
if (portNumber == null) {
return null;
}
ONOSLLDP lldp = getLinkProbe(portNumber, portDesc);
if (lldp == null) {
log.warn("Cannot get link probe with portNumber {} and portDesc {} for {} at BDDP packet creation.", portNumber, portDesc, deviceId);
return null;
}
bddpEth.setSourceMACAddress(context.fingerprint()).setPayload(lldp);
return new DefaultOutboundPacket(deviceId, builder().setOutput(portNumber(portNumber)).build(), ByteBuffer.wrap(bddpEth.serialize()));
}
use of org.onosproject.net.packet.DefaultOutboundPacket 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.onosproject.net.packet.DefaultOutboundPacket in project onos by opennetworkinglab.
the class DefaultHostProbingProvider method sendLocationProbe.
/**
* Send the probe packet on given port.
*
* @param probe the probe packet
* @param connectPoint the port we want to probe
*/
private void sendLocationProbe(Ethernet probe, ConnectPoint connectPoint) {
log.debug("Sending probe for host {} on location {} with probeMac {}", probe.getDestinationMAC(), connectPoint, probe.getSourceMAC());
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(connectPoint.port()).build();
OutboundPacket outboundPacket = new DefaultOutboundPacket(connectPoint.deviceId(), treatment, ByteBuffer.wrap(probe.serialize()));
packetService.emit(outboundPacket);
}
Aggregations