blob: 0330bc61bc0a2a2944ad012b7730734d1fb4d6f3 [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;
8import org.onlab.onos.net.flow.Instruction;
9import org.onlab.onos.net.flow.Instruction.Type;
alshabib030111e2014-09-15 15:56:42 -070010import org.onlab.onos.net.flow.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;
14import org.onlab.onos.of.controller.OpenFlowPacketContext;
15import 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) {
alshabib63d5afe2014-09-15 09:40:24 -070035 sendBufferedPacket();
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);
40 ofPktCtx.build(eth, OFPort.FLOOD);
41 }
alshabib63d5afe2014-09-15 09:40:24 -070042
alshabib1d4cace2014-09-13 19:16:26 -070043 }
44 }
45
alshabib63d5afe2014-09-15 09:40:24 -070046 private void sendBufferedPacket() {
47 List<Instruction> ins = treatmentBuilder().build().instructions();
48 OFPort p = null;
49 //TODO: support arbitrary list of treatments
50 for (Instruction i : ins) {
51 if (i.type() == Type.OUTPUT) {
alshabib030111e2014-09-15 15:56:42 -070052 p = buildPort(((OutputInstruction) i).port());
alshabib63d5afe2014-09-15 09:40:24 -070053 break; //for now...
54 }
55 }
56 ofPktCtx.build(p);
57 ofPktCtx.send();
58 }
59
60 private OFPort buildPort(PortNumber port) {
61 return OFPort.of((int) port.toLong());
62 }
63
alshabib1d4cace2014-09-13 19:16:26 -070064}