Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.packet; |
alshabib | f6d7796 | 2014-09-12 16:25:21 -0700 | [diff] [blame] | 17 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 18 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 19 | import org.onosproject.net.flow.TrafficTreatment; |
| 20 | import org.onosproject.net.flow.TrafficTreatment.Builder; |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 21 | |
Jonathan Hart | cc36be8 | 2015-04-09 11:54:56 -0700 | [diff] [blame] | 22 | import java.util.concurrent.atomic.AtomicBoolean; |
alshabib | f6d7796 | 2014-09-12 16:25:21 -0700 | [diff] [blame] | 23 | |
Jonathan Hart | cc36be8 | 2015-04-09 11:54:56 -0700 | [diff] [blame] | 24 | /** |
| 25 | * Default implementation of a packet context. |
| 26 | */ |
alshabib | f6d7796 | 2014-09-12 16:25:21 -0700 | [diff] [blame] | 27 | public abstract class DefaultPacketContext implements PacketContext { |
| 28 | |
| 29 | private final long time; |
| 30 | private final InboundPacket inPkt; |
| 31 | private final OutboundPacket outPkt; |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 32 | private final TrafficTreatment.Builder builder; |
| 33 | |
alshabib | 63d5afe | 2014-09-15 09:40:24 -0700 | [diff] [blame] | 34 | private final AtomicBoolean block; |
alshabib | f6d7796 | 2014-09-12 16:25:21 -0700 | [diff] [blame] | 35 | |
Jonathan Hart | cc36be8 | 2015-04-09 11:54:56 -0700 | [diff] [blame] | 36 | /** |
| 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 | */ |
alshabib | f6d7796 | 2014-09-12 16:25:21 -0700 | [diff] [blame] | 44 | 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; |
alshabib | 63d5afe | 2014-09-15 09:40:24 -0700 | [diff] [blame] | 50 | this.block = new AtomicBoolean(block); |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 51 | this.builder = DefaultTrafficTreatment.builder(); |
alshabib | f6d7796 | 2014-09-12 16:25:21 -0700 | [diff] [blame] | 52 | } |
| 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 |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 70 | public Builder treatmentBuilder() { |
| 71 | return builder; |
| 72 | } |
| 73 | |
| 74 | @Override |
alshabib | f6d7796 | 2014-09-12 16:25:21 -0700 | [diff] [blame] | 75 | public abstract void send(); |
| 76 | |
| 77 | @Override |
alshabib | 030111e | 2014-09-15 15:56:42 -0700 | [diff] [blame] | 78 | public boolean block() { |
alshabib | 63d5afe | 2014-09-15 09:40:24 -0700 | [diff] [blame] | 79 | return this.block.getAndSet(true); |
alshabib | f6d7796 | 2014-09-12 16:25:21 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | @Override |
| 83 | public boolean isHandled() { |
alshabib | 63d5afe | 2014-09-15 09:40:24 -0700 | [diff] [blame] | 84 | return this.block.get(); |
alshabib | f6d7796 | 2014-09-12 16:25:21 -0700 | [diff] [blame] | 85 | } |
alshabib | f6d7796 | 2014-09-12 16:25:21 -0700 | [diff] [blame] | 86 | } |