yoonseon | 5a51ef7 | 2016-10-26 14:50:09 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present 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 | */ |
| 16 | |
| 17 | package org.onosproject.incubator.net.virtual.impl.provider; |
| 18 | |
| 19 | import org.onosproject.incubator.net.virtual.NetworkId; |
| 20 | import org.onosproject.net.packet.DefaultPacketContext; |
| 21 | import org.onosproject.net.packet.InboundPacket; |
| 22 | import org.onosproject.net.packet.OutboundPacket; |
yoonseon | 5a51ef7 | 2016-10-26 14:50:09 -0700 | [diff] [blame] | 23 | |
| 24 | /** |
| 25 | * Represents context for processing an inbound packet for a virtual network |
| 26 | * and (optionally) emitting a corresponding outbound packet. |
| 27 | * The translation of context is handled by VirtualPacketProvider. |
| 28 | */ |
| 29 | public class VirtualPacketContext extends DefaultPacketContext { |
| 30 | private DefaultVirtualPacketProvider dvpp; |
| 31 | private NetworkId networkId; |
| 32 | |
| 33 | /** |
| 34 | * Creates a new packet context. |
| 35 | * |
| 36 | * @param time creation time |
| 37 | * @param inPkt inbound packet |
| 38 | * @param outPkt outbound packet |
| 39 | * @param block whether the context is blocked or not |
| 40 | * @param networkId virtual network ID where this context is handled |
| 41 | * @param dvpp The pointer for DefaultVirtualPacketProvider |
| 42 | */ |
| 43 | |
| 44 | protected VirtualPacketContext(long time, InboundPacket inPkt, |
| 45 | OutboundPacket outPkt, boolean block, |
| 46 | NetworkId networkId, |
| 47 | DefaultVirtualPacketProvider dvpp) { |
| 48 | super(time, inPkt, outPkt, block); |
| 49 | |
| 50 | this.networkId = networkId; |
| 51 | this.dvpp = dvpp; |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public void send() { |
| 56 | if (!this.block()) { |
Yoonseon Han | c8089db | 2017-03-22 20:22:12 +0900 | [diff] [blame^] | 57 | dvpp.devirtualizeContext(this); |
yoonseon | 5a51ef7 | 2016-10-26 14:50:09 -0700 | [diff] [blame] | 58 | } |
| 59 | } |
| 60 | |
| 61 | public NetworkId getNetworkId() { |
| 62 | return networkId; |
| 63 | } |
| 64 | } |