use of org.onosproject.net.packet.DefaultOutboundPacket in project onos by opennetworkinglab.
the class TunnellingConnectivityManager method forward.
/**
* Forwards a BGP packet to another connect point.
*
* @param context the packet context of the incoming packet
*/
private void forward(PacketContext context) {
ConnectPoint outputPort = null;
IPv4 ipv4 = (IPv4) context.inPacket().parsed().getPayload();
IpAddress dstAddress = IpAddress.valueOf(ipv4.getDestinationAddress());
if (context.inPacket().receivedFrom().equals(bgpSpeaker.connectPoint())) {
if (bgpSpeaker.peers().contains(dstAddress)) {
Interface intf = interfaceService.getMatchingInterface(dstAddress);
if (intf != null) {
outputPort = intf.connectPoint();
}
}
} else {
Set<Interface> interfaces = interfaceService.getInterfacesByPort(context.inPacket().receivedFrom());
if (interfaces.stream().flatMap(intf -> intf.ipAddressesList().stream()).anyMatch(ia -> ia.ipAddress().equals(dstAddress))) {
outputPort = bgpSpeaker.connectPoint();
}
}
if (outputPort != null) {
TrafficTreatment t = DefaultTrafficTreatment.builder().setOutput(outputPort.port()).build();
OutboundPacket o = new DefaultOutboundPacket(outputPort.deviceId(), t, context.inPacket().unparsed());
packetService.emit(o);
}
}
use of org.onosproject.net.packet.DefaultOutboundPacket in project onos by opennetworkinglab.
the class IcmpHandler method sendPacketOut.
private void sendPacketOut(ConnectPoint outport, Ethernet payload) {
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(outport.port()).build();
OutboundPacket packet = new DefaultOutboundPacket(outport.deviceId(), treatment, ByteBuffer.wrap(payload.serialize()));
packetService.emit(packet);
}
use of org.onosproject.net.packet.DefaultOutboundPacket in project onos by opennetworkinglab.
the class FabricInterpreterTest method testMapOutboundPacketWithForwarding.
@Test
public void testMapOutboundPacketWithForwarding() throws Exception {
PortNumber outputPort = PortNumber.TABLE;
TrafficTreatment outputTreatment = DefaultTrafficTreatment.builder().setOutput(outputPort).build();
ByteBuffer data = ByteBuffer.allocate(64);
OutboundPacket outPkt = new DefaultOutboundPacket(DEVICE_ID, outputTreatment, data);
Collection<PiPacketOperation> result = interpreter.mapOutboundPacket(outPkt);
assertEquals(result.size(), 1);
ImmutableList.Builder<PiPacketMetadata> builder = ImmutableList.builder();
builder.add(PiPacketMetadata.builder().withId(FabricConstants.DO_FORWARDING).withValue(ImmutableByteSequence.copyFrom(1).fit(1)).build());
PiPacketOperation expectedPktOp = PiPacketOperation.builder().withType(PiPacketOperationType.PACKET_OUT).withData(ImmutableByteSequence.copyFrom(data)).withMetadatas(builder.build()).build();
assertEquals(expectedPktOp, result.iterator().next());
}
use of org.onosproject.net.packet.DefaultOutboundPacket in project onos by opennetworkinglab.
the class FabricInterpreterTest method testMapOutboundPacketWithoutForwarding.
@Test
public void testMapOutboundPacketWithoutForwarding() throws Exception {
PortNumber outputPort = PortNumber.portNumber(1);
TrafficTreatment outputTreatment = DefaultTrafficTreatment.builder().setOutput(outputPort).build();
ByteBuffer data = ByteBuffer.allocate(64);
OutboundPacket outPkt = new DefaultOutboundPacket(DEVICE_ID, outputTreatment, data);
Collection<PiPacketOperation> result = interpreter.mapOutboundPacket(outPkt);
assertEquals(result.size(), 1);
ImmutableList.Builder<PiPacketMetadata> builder = ImmutableList.builder();
builder.add(PiPacketMetadata.builder().withId(FabricConstants.EGRESS_PORT).withValue(ImmutableByteSequence.copyFrom(outputPort.toLong()).fit(PORT_BITWIDTH)).build());
PiPacketOperation expectedPktOp = PiPacketOperation.builder().withType(PiPacketOperationType.PACKET_OUT).withData(ImmutableByteSequence.copyFrom(data)).withMetadatas(builder.build()).build();
assertEquals(expectedPktOp, result.iterator().next());
}
use of org.onosproject.net.packet.DefaultOutboundPacket in project onos by opennetworkinglab.
the class KubevirtRoutingArpHandler method retrievePeerRouterMac.
/**
* Triggers ARP request to retrieve the peer router mac address.
*
* @param router kubevirt router
* @param peerRouterIp peer router IP address
*/
private void retrievePeerRouterMac(KubevirtRouter router, IpAddress peerRouterIp) {
log.info("Sending ARP request to the peer router {} to retrieve the MAC address.", peerRouterIp.getIp4Address().toString());
String routerSnatIp = router.external().keySet().stream().findAny().orElse(null);
if (routerSnatIp == null) {
return;
}
IpAddress sourceIp = IpAddress.valueOf(routerSnatIp);
MacAddress sourceMac = DEFAULT_GATEWAY_MAC;
Ethernet ethRequest = ARP.buildArpRequest(sourceMac.toBytes(), sourceIp.toOctets(), peerRouterIp.toOctets(), VlanId.NO_VID);
KubevirtNode gatewayNode = kubevirtNodeService.node(router.electedGateway());
if (gatewayNode == null) {
return;
}
PortNumber externalPatchPortNum = KubevirtNetworkingUtil.externalPatchPortNum(deviceService, gatewayNode);
if (externalPatchPortNum == null) {
return;
}
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(externalPatchPortNum).build();
packetService.emit(new DefaultOutboundPacket(gatewayNode.intgBridge(), treatment, ByteBuffer.wrap(ethRequest.serialize())));
}
Aggregations