Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
alshabib | f6d7796 | 2014-09-12 16:25:21 -0700 | [diff] [blame] | 16 | package org.onlab.onos.net.packet; |
| 17 | |
alshabib | 63d5afe | 2014-09-15 09:40:24 -0700 | [diff] [blame] | 18 | import java.util.concurrent.atomic.AtomicBoolean; |
| 19 | |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 20 | import org.onlab.onos.net.flow.DefaultTrafficTreatment; |
| 21 | import org.onlab.onos.net.flow.TrafficTreatment; |
| 22 | import org.onlab.onos.net.flow.TrafficTreatment.Builder; |
| 23 | |
alshabib | f6d7796 | 2014-09-12 16:25:21 -0700 | [diff] [blame] | 24 | |
| 25 | public abstract class DefaultPacketContext implements PacketContext { |
| 26 | |
| 27 | private final long time; |
| 28 | private final InboundPacket inPkt; |
| 29 | private final OutboundPacket outPkt; |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 30 | private final TrafficTreatment.Builder builder; |
| 31 | |
alshabib | 63d5afe | 2014-09-15 09:40:24 -0700 | [diff] [blame] | 32 | private final AtomicBoolean block; |
alshabib | f6d7796 | 2014-09-12 16:25:21 -0700 | [diff] [blame] | 33 | |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 34 | |
alshabib | f6d7796 | 2014-09-12 16:25:21 -0700 | [diff] [blame] | 35 | 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; |
alshabib | 63d5afe | 2014-09-15 09:40:24 -0700 | [diff] [blame] | 41 | this.block = new AtomicBoolean(block); |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 42 | this.builder = DefaultTrafficTreatment.builder(); |
alshabib | f6d7796 | 2014-09-12 16:25:21 -0700 | [diff] [blame] | 43 | } |
| 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 |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 61 | public Builder treatmentBuilder() { |
| 62 | return builder; |
| 63 | } |
| 64 | |
| 65 | @Override |
alshabib | f6d7796 | 2014-09-12 16:25:21 -0700 | [diff] [blame] | 66 | public abstract void send(); |
| 67 | |
| 68 | @Override |
alshabib | 030111e | 2014-09-15 15:56:42 -0700 | [diff] [blame] | 69 | public boolean block() { |
alshabib | 63d5afe | 2014-09-15 09:40:24 -0700 | [diff] [blame] | 70 | return this.block.getAndSet(true); |
alshabib | f6d7796 | 2014-09-12 16:25:21 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public boolean isHandled() { |
alshabib | 63d5afe | 2014-09-15 09:40:24 -0700 | [diff] [blame] | 75 | return this.block.get(); |
alshabib | f6d7796 | 2014-09-12 16:25:21 -0700 | [diff] [blame] | 76 | } |
alshabib | f6d7796 | 2014-09-12 16:25:21 -0700 | [diff] [blame] | 77 | } |