blob: a77aebcb980a41bcb56c2950825f352ffecac249 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
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'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.packet;
tom613d8142014-09-11 15:09:37 -070017
18/**
19 * Abstraction of an inbound packet processor.
20 */
21public interface PacketProcessor {
22
Sho SHIMIZU3310a342015-05-13 12:14:05 -070023 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;
alshabib369d2942014-09-12 17:59:35 -070026
tom613d8142014-09-11 15:09:37 -070027 /**
samanwita palf5286362015-07-29 12:59:00 -070028 * 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 /**
tom613d8142014-09-11 15:09:37 -070074 * 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}