samanwita pal
Committed by Gerrit Code Review

Changing the packet ordering scheme so that it doesn't require absolute numbers

Change-Id: If459966d2b0e81ec4b8ceabe22a93fe27d4e9030
...@@ -15,8 +15,6 @@ ...@@ -15,8 +15,6 @@
15 */ 15 */
16 package org.onosproject.net.packet; 16 package org.onosproject.net.packet;
17 17
18 -
19 -
20 /** 18 /**
21 * Abstraction of an inbound packet processor. 19 * Abstraction of an inbound packet processor.
22 */ 20 */
...@@ -27,6 +25,52 @@ public interface PacketProcessor { ...@@ -27,6 +25,52 @@ public interface PacketProcessor {
27 static final int OBSERVER_MAX = Integer.MAX_VALUE; 25 static final int OBSERVER_MAX = Integer.MAX_VALUE;
28 26
29 /** 27 /**
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 + /**
30 * Processes the inbound packet as specified in the given context. 74 * Processes the inbound packet as specified in the given context.
31 * 75 *
32 * @param context packet processing context 76 * @param context packet processing context
......