blob: eba8e8e58bbabcea7deff4c0387123b0adf51da6 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 Open Networking Laboratory
3 *
4 * 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
7 *
8 * 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.
15 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.packet;
alshabibf6d77962014-09-12 16:25:21 -070017
alshabib63d5afe2014-09-15 09:40:24 -070018import java.util.concurrent.atomic.AtomicBoolean;
19
Brian O'Connorabafb502014-12-02 22:26:20 -080020import org.onosproject.net.flow.DefaultTrafficTreatment;
21import org.onosproject.net.flow.TrafficTreatment;
22import org.onosproject.net.flow.TrafficTreatment.Builder;
alshabib1d4cace2014-09-13 19:16:26 -070023
alshabibf6d77962014-09-12 16:25:21 -070024
25public abstract class DefaultPacketContext implements PacketContext {
26
27 private final long time;
28 private final InboundPacket inPkt;
29 private final OutboundPacket outPkt;
alshabib1d4cace2014-09-13 19:16:26 -070030 private final TrafficTreatment.Builder builder;
31
alshabib63d5afe2014-09-15 09:40:24 -070032 private final AtomicBoolean block;
alshabibf6d77962014-09-12 16:25:21 -070033
alshabib1d4cace2014-09-13 19:16:26 -070034
alshabibf6d77962014-09-12 16:25:21 -070035 protected DefaultPacketContext(long time, InboundPacket inPkt,
36 OutboundPacket outPkt, boolean block) {
37 super();
38 this.time = time;
39 this.inPkt = inPkt;
40 this.outPkt = outPkt;
alshabib63d5afe2014-09-15 09:40:24 -070041 this.block = new AtomicBoolean(block);
tom9a693fd2014-10-03 11:32:19 -070042 this.builder = DefaultTrafficTreatment.builder();
alshabibf6d77962014-09-12 16:25:21 -070043 }
44
45 @Override
46 public long time() {
47 return time;
48 }
49
50 @Override
51 public InboundPacket inPacket() {
52 return inPkt;
53 }
54
55 @Override
56 public OutboundPacket outPacket() {
57 return outPkt;
58 }
59
60 @Override
alshabib1d4cace2014-09-13 19:16:26 -070061 public Builder treatmentBuilder() {
62 return builder;
63 }
64
65 @Override
alshabibf6d77962014-09-12 16:25:21 -070066 public abstract void send();
67
68 @Override
alshabib030111e2014-09-15 15:56:42 -070069 public boolean block() {
alshabib63d5afe2014-09-15 09:40:24 -070070 return this.block.getAndSet(true);
alshabibf6d77962014-09-12 16:25:21 -070071 }
72
73 @Override
74 public boolean isHandled() {
alshabib63d5afe2014-09-15 09:40:24 -070075 return this.block.get();
alshabibf6d77962014-09-12 16:25:21 -070076 }
alshabibf6d77962014-09-12 16:25:21 -070077}