blob: e7c44432492b61e16d18aaf5753344b30576f46f [file] [log] [blame]
alshabib1d4cace2014-09-13 19:16:26 -07001package org.onlab.onos.provider.of.packet.impl;
2
3import static org.slf4j.LoggerFactory.getLogger;
4
alshabib63d5afe2014-09-15 09:40:24 -07005import java.util.List;
6
7import org.onlab.onos.net.PortNumber;
alshabib55a55d92014-09-16 11:59:31 -07008import org.onlab.onos.net.flow.instructions.Instruction;
9import org.onlab.onos.net.flow.instructions.Instruction.Type;
10import org.onlab.onos.net.flow.instructions.Instructions.OutputInstruction;
alshabib1d4cace2014-09-13 19:16:26 -070011import org.onlab.onos.net.packet.DefaultPacketContext;
12import org.onlab.onos.net.packet.InboundPacket;
13import org.onlab.onos.net.packet.OutboundPacket;
tom9c94c5b2014-09-17 13:14:42 -070014import org.onlab.onos.openflow.controller.OpenFlowPacketContext;
alshabib1d4cace2014-09-13 19:16:26 -070015import org.onlab.packet.Ethernet;
16import org.projectfloodlight.openflow.types.OFPort;
17import org.slf4j.Logger;
18
19public class OpenFlowCorePacketContext extends DefaultPacketContext {
20
21 private final Logger log = getLogger(getClass());
22
23 private final OpenFlowPacketContext ofPktCtx;
24
25 protected OpenFlowCorePacketContext(long time, InboundPacket inPkt,
26 OutboundPacket outPkt, boolean block, OpenFlowPacketContext ofPktCtx) {
27 super(time, inPkt, outPkt, block);
28 this.ofPktCtx = ofPktCtx;
29 }
30
31 @Override
32 public void send() {
alshabib030111e2014-09-15 15:56:42 -070033 if (!this.block()) {
alshabib1d4cace2014-09-13 19:16:26 -070034 if (outPacket() == null) {
alshabibe9d3a322014-09-23 15:18:33 -070035 sendPacket(null);
alshabib1d4cace2014-09-13 19:16:26 -070036 } else {
37 Ethernet eth = new Ethernet();
38 eth.deserialize(outPacket().data().array(), 0,
39 outPacket().data().array().length);
alshabibe9d3a322014-09-23 15:18:33 -070040 sendPacket(eth);
41
alshabib1d4cace2014-09-13 19:16:26 -070042 }
alshabib63d5afe2014-09-15 09:40:24 -070043
alshabib1d4cace2014-09-13 19:16:26 -070044 }
45 }
46
alshabibe9d3a322014-09-23 15:18:33 -070047 private void sendPacket(Ethernet eth) {
alshabib63d5afe2014-09-15 09:40:24 -070048 List<Instruction> ins = treatmentBuilder().build().instructions();
49 OFPort p = null;
alshabib8f1cf4a2014-09-17 14:44:48 -070050 //TODO: support arbitrary list of treatments must be supported in ofPacketContext
alshabib63d5afe2014-09-15 09:40:24 -070051 for (Instruction i : ins) {
52 if (i.type() == Type.OUTPUT) {
alshabib030111e2014-09-15 15:56:42 -070053 p = buildPort(((OutputInstruction) i).port());
alshabib63d5afe2014-09-15 09:40:24 -070054 break; //for now...
55 }
56 }
alshabibe9d3a322014-09-23 15:18:33 -070057 if (eth == null) {
58 ofPktCtx.build(p);
59 } else {
60 ofPktCtx.build(eth, p);
61 }
alshabib63d5afe2014-09-15 09:40:24 -070062 ofPktCtx.send();
63 }
alshabib63d5afe2014-09-15 09:40:24 -070064 private OFPort buildPort(PortNumber port) {
65 return OFPort.of((int) port.toLong());
66 }
67
alshabib1d4cace2014-09-13 19:16:26 -070068}