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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.packet; |
tom | 613d814 | 2014-09-11 15:09:37 -0700 | [diff] [blame] | 17 | |
| 18 | /** |
| 19 | * Abstraction of an inbound packet processor. |
| 20 | */ |
| 21 | public interface PacketProcessor { |
| 22 | |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 23 | static final int ADVISOR_MAX = Integer.MAX_VALUE / 3; |
| 24 | static final int DIRECTOR_MAX = (Integer.MAX_VALUE / 3) * 2; |
| 25 | static final int OBSERVER_MAX = Integer.MAX_VALUE; |
alshabib | 369d294 | 2014-09-12 17:59:35 -0700 | [diff] [blame] | 26 | |
tom | 613d814 | 2014-09-11 15:09:37 -0700 | [diff] [blame] | 27 | /** |
samanwita pal | f528636 | 2015-07-29 12:59:00 -0700 | [diff] [blame^] | 28 | * Returns a priority in the ADVISOR range, where processors can take early action and |
| 29 | * influence the packet context. However, they cannot handle the packet (i.e. call send() or block()). |
| 30 | * Processors in this range get to see the packet first. |
| 31 | * |
| 32 | * @param priority priority within ADVISOR range |
| 33 | * @return overall priority |
| 34 | */ |
| 35 | static int advisor(int priority) { |
| 36 | if (priority > 0 && priority <= ADVISOR_MAX) { |
| 37 | return priority; |
| 38 | } |
| 39 | return ADVISOR_MAX; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Returns a priority in the DIRECTOR range, where processors can handle the packet. |
| 44 | * Processors in this range get to see the packet second, after ADVISORS. |
| 45 | * |
| 46 | * @param priority priority within the DIRECTOR range |
| 47 | * @return overall priority |
| 48 | */ |
| 49 | static int director(int priority) { |
| 50 | int overallPriority = ADVISOR_MAX + priority; |
| 51 | if (overallPriority > ADVISOR_MAX && overallPriority <= DIRECTOR_MAX) { |
| 52 | return overallPriority; |
| 53 | } |
| 54 | return DIRECTOR_MAX; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Returns a priority in the OBSERVER range, where processors cannot take any action, |
| 59 | * but can observe what action has been taken until then. |
| 60 | * Processors in this range get to see the packet last, after ADVISORS and DIRECTORS. |
| 61 | * |
| 62 | * @param priority priority within the OBSERVER range |
| 63 | * @return overall priority |
| 64 | */ |
| 65 | static int observer(int priority) { |
| 66 | int overallPriority = DIRECTOR_MAX + priority; |
| 67 | if (overallPriority > DIRECTOR_MAX && overallPriority <= OBSERVER_MAX) { |
| 68 | return overallPriority; |
| 69 | } |
| 70 | return OBSERVER_MAX; |
| 71 | } |
| 72 | |
| 73 | /** |
tom | 613d814 | 2014-09-11 15:09:37 -0700 | [diff] [blame] | 74 | * Processes the inbound packet as specified in the given context. |
| 75 | * |
| 76 | * @param context packet processing context |
| 77 | */ |
| 78 | void process(PacketContext context); |
| 79 | |
| 80 | } |