blob: ffea2d8ee7c4d3c5ed7c0e0b5bdfa93103b5c00e [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 Open Networking Laboratory
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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
Brian O'Connorabafb502014-12-02 22:26:20 -080018import org.onosproject.net.flow.DefaultTrafficTreatment;
19import org.onosproject.net.flow.TrafficTreatment;
20import org.onosproject.net.flow.TrafficTreatment.Builder;
alshabib1d4cace2014-09-13 19:16:26 -070021
Jonathan Hartcc36be82015-04-09 11:54:56 -070022import java.util.concurrent.atomic.AtomicBoolean;
alshabibf6d77962014-09-12 16:25:21 -070023
Jonathan Hartcc36be82015-04-09 11:54:56 -070024/**
25 * Default implementation of a packet context.
26 */
alshabibf6d77962014-09-12 16:25:21 -070027public abstract class DefaultPacketContext implements PacketContext {
28
29 private final long time;
30 private final InboundPacket inPkt;
31 private final OutboundPacket outPkt;
alshabib1d4cace2014-09-13 19:16:26 -070032 private final TrafficTreatment.Builder builder;
33
alshabib63d5afe2014-09-15 09:40:24 -070034 private final AtomicBoolean block;
alshabibf6d77962014-09-12 16:25:21 -070035
Jonathan Hartcc36be82015-04-09 11:54:56 -070036 /**
37 * Creates a new packet context.
38 *
39 * @param time creation time
40 * @param inPkt inbound packet
41 * @param outPkt outbound packet
42 * @param block whether the context is blocked or not
43 */
alshabibf6d77962014-09-12 16:25:21 -070044 protected DefaultPacketContext(long time, InboundPacket inPkt,
45 OutboundPacket outPkt, boolean block) {
46 super();
47 this.time = time;
48 this.inPkt = inPkt;
49 this.outPkt = outPkt;
alshabib63d5afe2014-09-15 09:40:24 -070050 this.block = new AtomicBoolean(block);
tom9a693fd2014-10-03 11:32:19 -070051 this.builder = DefaultTrafficTreatment.builder();
alshabibf6d77962014-09-12 16:25:21 -070052 }
53
54 @Override
55 public long time() {
56 return time;
57 }
58
59 @Override
60 public InboundPacket inPacket() {
61 return inPkt;
62 }
63
64 @Override
65 public OutboundPacket outPacket() {
66 return outPkt;
67 }
68
69 @Override
alshabib1d4cace2014-09-13 19:16:26 -070070 public Builder treatmentBuilder() {
71 return builder;
72 }
73
74 @Override
alshabibf6d77962014-09-12 16:25:21 -070075 public abstract void send();
76
77 @Override
alshabib030111e2014-09-15 15:56:42 -070078 public boolean block() {
alshabib63d5afe2014-09-15 09:40:24 -070079 return this.block.getAndSet(true);
alshabibf6d77962014-09-12 16:25:21 -070080 }
81
82 @Override
83 public boolean isHandled() {
alshabib63d5afe2014-09-15 09:40:24 -070084 return this.block.get();
alshabibf6d77962014-09-12 16:25:21 -070085 }
alshabibf6d77962014-09-12 16:25:21 -070086}