use of org.onosproject.net.packet.InboundPacket in project onos by opennetworkinglab.
the class OpenstackRoutingSnatHandler method processSnatPacket.
private void processSnatPacket(PacketContext context, Ethernet eth) {
if (getStatefulSnatFlag()) {
return;
}
IPv4 iPacket = (IPv4) eth.getPayload();
InboundPacket packetIn = context.inPacket();
int patPort = getPortNum();
InstancePort srcInstPort = instancePortService.instancePort(eth.getSourceMAC());
if (srcInstPort == null) {
log.error(ERR_PACKET_IN + "source host(MAC:{}) does not exist", eth.getSourceMAC());
return;
}
IpAddress srcIp = IpAddress.valueOf(iPacket.getSourceAddress());
Subnet srcSubnet = getSourceSubnet(srcInstPort, srcIp);
Router osRouter = getRouterFromSubnet(srcSubnet, osRouterService);
if (osRouter == null || osRouter.getExternalGatewayInfo() == null) {
// this router does not have external connectivity
log.warn("No router is associated with the given subnet {}", srcSubnet);
return;
}
IpAddress externalGatewayIp = externalGatewayIpSnatEnabled(osRouter, osNetworkAdminService);
if (externalGatewayIp == null) {
return;
}
ExternalPeerRouter externalPeerRouter = externalPeerRouterFromSubnet(srcSubnet, osRouterService, osNetworkService);
if (externalPeerRouter == null) {
return;
}
populateSnatFlowRules(context.inPacket(), srcInstPort, TpPort.tpPort(patPort), externalGatewayIp, externalPeerRouter);
packetOut(eth.duplicate(), packetIn.receivedFrom().deviceId(), patPort, externalGatewayIp, externalPeerRouter);
}
use of org.onosproject.net.packet.InboundPacket in project onos by opennetworkinglab.
the class OpenstackRoutingSnatIcmpHandlerTest method sendPacket.
private void sendPacket(Ethernet ethernet) {
final ByteBuffer byteBuffer = ByteBuffer.wrap(ethernet.serialize());
InboundPacket inPacket = new DefaultInboundPacket(connectPoint(srcDeviceId1.toString(), Integer.parseInt(srcPortNum1.toString())), ethernet, byteBuffer);
PacketContext context = new TestPacketContext(127L, inPacket, null, false);
packetProcessor.process(context);
}
use of org.onosproject.net.packet.InboundPacket in project onos by opennetworkinglab.
the class OpenstackSwitchingArpHandlerTest method sendPacket.
/**
* Sends an Ethernet packet to the process method of the Packet processor.
*
* @param ethernet Ethernet packet
*/
private void sendPacket(Ethernet ethernet) {
final ByteBuffer byteBuffer = ByteBuffer.wrap(ethernet.serialize());
InboundPacket inPacket = new DefaultInboundPacket(connectPoint("1", 1), ethernet, byteBuffer);
PacketContext context = new TestPacketContext(127L, inPacket, null, false);
packetProcessor.process(context);
}
use of org.onosproject.net.packet.InboundPacket in project onos by opennetworkinglab.
the class OpenstackSwitchingDhcpHandlerTest method sendPacket.
/**
* Sends an Ethernet packet to the process method of the Packet Processor.
*
* @param ethernet Ethernet packet
*/
private void sendPacket(Ethernet ethernet) {
final ByteBuffer byteBuffer = ByteBuffer.wrap(ethernet.serialize());
InboundPacket inPacket = new DefaultInboundPacket(connectPoint("1", 1), ethernet, byteBuffer);
PacketContext context = new TestPacketContext(127L, inPacket, null, false);
packetProcessor.process(context);
}
use of org.onosproject.net.packet.InboundPacket in project onos by opennetworkinglab.
the class MQUtil method json.
/**
* Returns a JSON representation of the given packet context.
*
* @param context the packet context
* @return the inbound packetjson message
*/
public static JsonObject json(PacketContext context) {
JsonObject jo = new JsonObject();
InboundPacket pkt = context.inPacket();
// parse connection host
jo.addProperty(SWITCH_ID, pkt.receivedFrom().deviceId().toString());
jo.addProperty(IN_PORT, pkt.receivedFrom().port().name());
jo.addProperty(LOGICAL, pkt.receivedFrom().port().isLogical());
jo.addProperty(RECEIVED, new Date(context.time()).toString());
jo.addProperty(MSG_TYPE, PKT_TYPE);
// parse ethernet
jo.addProperty(SUB_MSG_TYPE, EthType.EtherType.lookup(pkt.parsed().getEtherType()).name());
jo.addProperty(ETH_TYPE, pkt.parsed().getEtherType());
jo.addProperty(SRC_MAC_ADDR, pkt.parsed().getSourceMAC().toString());
jo.addProperty(DEST_MAC_ADDR, pkt.parsed().getDestinationMAC().toString());
jo.addProperty(VLAN_ID, pkt.parsed().getVlanID());
jo.addProperty(B_CAST, pkt.parsed().isBroadcast());
jo.addProperty(M_CAST, pkt.parsed().isMulticast());
jo.addProperty(PAD, pkt.parsed().isPad());
jo.addProperty(PRIORITY_CODE, pkt.parsed().getPriorityCode());
// parse bytebuffer
jo.addProperty(DATA_LEN, pkt.unparsed().array().length);
jo.addProperty(PAYLOAD, pkt.unparsed().asCharBuffer().toString());
return jo;
}
Aggregations