blob: 7189fd83f8caa1b4a90e3241629edbe360dbcebe [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska781d18b2014-10-27 10:31:25 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
Thomas Vachuska781d18b2014-10-27 10:31:25 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
Thomas Vachuska781d18b2014-10-27 10:31:25 -070015 */
alshabib1d4cace2014-09-13 19:16:26 -070016package org.onlab.onos.provider.of.packet.impl;
17
alshabib63d5afe2014-09-15 09:40:24 -070018import org.onlab.onos.net.PortNumber;
alshabib55a55d92014-09-16 11:59:31 -070019import org.onlab.onos.net.flow.instructions.Instruction;
20import org.onlab.onos.net.flow.instructions.Instruction.Type;
21import org.onlab.onos.net.flow.instructions.Instructions.OutputInstruction;
alshabib1d4cace2014-09-13 19:16:26 -070022import org.onlab.onos.net.packet.DefaultPacketContext;
23import org.onlab.onos.net.packet.InboundPacket;
24import org.onlab.onos.net.packet.OutboundPacket;
tom9c94c5b2014-09-17 13:14:42 -070025import org.onlab.onos.openflow.controller.OpenFlowPacketContext;
alshabib1d4cace2014-09-13 19:16:26 -070026import org.onlab.packet.Ethernet;
27import org.projectfloodlight.openflow.types.OFPort;
tom1679e182014-10-09 13:50:45 -070028
29import java.util.List;
alshabib1d4cace2014-09-13 19:16:26 -070030
31public class OpenFlowCorePacketContext extends DefaultPacketContext {
32
alshabib1d4cace2014-09-13 19:16:26 -070033 private final OpenFlowPacketContext ofPktCtx;
34
35 protected OpenFlowCorePacketContext(long time, InboundPacket inPkt,
tom1679e182014-10-09 13:50:45 -070036 OutboundPacket outPkt, boolean block,
37 OpenFlowPacketContext ofPktCtx) {
alshabib1d4cace2014-09-13 19:16:26 -070038 super(time, inPkt, outPkt, block);
39 this.ofPktCtx = ofPktCtx;
40 }
41
42 @Override
43 public void send() {
alshabib030111e2014-09-15 15:56:42 -070044 if (!this.block()) {
alshabib1d4cace2014-09-13 19:16:26 -070045 if (outPacket() == null) {
alshabibe9d3a322014-09-23 15:18:33 -070046 sendPacket(null);
alshabib1d4cace2014-09-13 19:16:26 -070047 } else {
48 Ethernet eth = new Ethernet();
49 eth.deserialize(outPacket().data().array(), 0,
tom1679e182014-10-09 13:50:45 -070050 outPacket().data().array().length);
alshabibe9d3a322014-09-23 15:18:33 -070051 sendPacket(eth);
alshabib1d4cace2014-09-13 19:16:26 -070052 }
alshabib63d5afe2014-09-15 09:40:24 -070053
alshabib1d4cace2014-09-13 19:16:26 -070054 }
55 }
56
alshabibe9d3a322014-09-23 15:18:33 -070057 private void sendPacket(Ethernet eth) {
alshabib63d5afe2014-09-15 09:40:24 -070058 List<Instruction> ins = treatmentBuilder().build().instructions();
59 OFPort p = null;
alshabib8f1cf4a2014-09-17 14:44:48 -070060 //TODO: support arbitrary list of treatments must be supported in ofPacketContext
alshabib63d5afe2014-09-15 09:40:24 -070061 for (Instruction i : ins) {
62 if (i.type() == Type.OUTPUT) {
alshabib030111e2014-09-15 15:56:42 -070063 p = buildPort(((OutputInstruction) i).port());
alshabib63d5afe2014-09-15 09:40:24 -070064 break; //for now...
65 }
66 }
alshabibe9d3a322014-09-23 15:18:33 -070067 if (eth == null) {
68 ofPktCtx.build(p);
69 } else {
70 ofPktCtx.build(eth, p);
71 }
alshabib63d5afe2014-09-15 09:40:24 -070072 ofPktCtx.send();
73 }
tom1679e182014-10-09 13:50:45 -070074
alshabib63d5afe2014-09-15 09:40:24 -070075 private OFPort buildPort(PortNumber port) {
76 return OFPort.of((int) port.toLong());
77 }
78
alshabib1d4cace2014-09-13 19:16:26 -070079}