blob: 71ddb0d662277d067a2140c27095343c176102df [file] [log] [blame]
alshabib1d4cace2014-09-13 19:16:26 -07001package org.onlab.onos.provider.of.packet.impl;
2
alshabib63d5afe2014-09-15 09:40:24 -07003import org.onlab.onos.net.PortNumber;
alshabib55a55d92014-09-16 11:59:31 -07004import org.onlab.onos.net.flow.instructions.Instruction;
5import org.onlab.onos.net.flow.instructions.Instruction.Type;
6import org.onlab.onos.net.flow.instructions.Instructions.OutputInstruction;
alshabib1d4cace2014-09-13 19:16:26 -07007import org.onlab.onos.net.packet.DefaultPacketContext;
8import org.onlab.onos.net.packet.InboundPacket;
9import org.onlab.onos.net.packet.OutboundPacket;
tom9c94c5b2014-09-17 13:14:42 -070010import org.onlab.onos.openflow.controller.OpenFlowPacketContext;
alshabib1d4cace2014-09-13 19:16:26 -070011import org.onlab.packet.Ethernet;
12import org.projectfloodlight.openflow.types.OFPort;
tom1679e182014-10-09 13:50:45 -070013
14import java.util.List;
alshabib1d4cace2014-09-13 19:16:26 -070015
16public class OpenFlowCorePacketContext extends DefaultPacketContext {
17
alshabib1d4cace2014-09-13 19:16:26 -070018 private final OpenFlowPacketContext ofPktCtx;
19
20 protected OpenFlowCorePacketContext(long time, InboundPacket inPkt,
tom1679e182014-10-09 13:50:45 -070021 OutboundPacket outPkt, boolean block,
22 OpenFlowPacketContext ofPktCtx) {
alshabib1d4cace2014-09-13 19:16:26 -070023 super(time, inPkt, outPkt, block);
24 this.ofPktCtx = ofPktCtx;
25 }
26
27 @Override
28 public void send() {
alshabib030111e2014-09-15 15:56:42 -070029 if (!this.block()) {
alshabib1d4cace2014-09-13 19:16:26 -070030 if (outPacket() == null) {
alshabibe9d3a322014-09-23 15:18:33 -070031 sendPacket(null);
alshabib1d4cace2014-09-13 19:16:26 -070032 } else {
33 Ethernet eth = new Ethernet();
34 eth.deserialize(outPacket().data().array(), 0,
tom1679e182014-10-09 13:50:45 -070035 outPacket().data().array().length);
alshabibe9d3a322014-09-23 15:18:33 -070036 sendPacket(eth);
alshabib1d4cace2014-09-13 19:16:26 -070037 }
alshabib63d5afe2014-09-15 09:40:24 -070038
alshabib1d4cace2014-09-13 19:16:26 -070039 }
40 }
41
alshabibe9d3a322014-09-23 15:18:33 -070042 private void sendPacket(Ethernet eth) {
alshabib63d5afe2014-09-15 09:40:24 -070043 List<Instruction> ins = treatmentBuilder().build().instructions();
44 OFPort p = null;
alshabib8f1cf4a2014-09-17 14:44:48 -070045 //TODO: support arbitrary list of treatments must be supported in ofPacketContext
alshabib63d5afe2014-09-15 09:40:24 -070046 for (Instruction i : ins) {
47 if (i.type() == Type.OUTPUT) {
alshabib030111e2014-09-15 15:56:42 -070048 p = buildPort(((OutputInstruction) i).port());
alshabib63d5afe2014-09-15 09:40:24 -070049 break; //for now...
50 }
51 }
alshabibe9d3a322014-09-23 15:18:33 -070052 if (eth == null) {
53 ofPktCtx.build(p);
54 } else {
55 ofPktCtx.build(eth, p);
56 }
alshabib63d5afe2014-09-15 09:40:24 -070057 ofPktCtx.send();
58 }
tom1679e182014-10-09 13:50:45 -070059
alshabib63d5afe2014-09-15 09:40:24 -070060 private OFPort buildPort(PortNumber port) {
61 return OFPort.of((int) port.toLong());
62 }
63
alshabib1d4cace2014-09-13 19:16:26 -070064}