samanwita pal
Committed by Gerrit Code Review

Changing packet ordering scheme in PacketProcessor

Change-Id: I54741f3ab4c17094ed748e00e9058adb161d309f
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
15 */ 15 */
16 package org.onosproject.net.packet; 16 package org.onosproject.net.packet;
17 17
18 +import static com.google.common.base.Preconditions.checkArgument;
19 +
18 /** 20 /**
19 * Abstraction of an inbound packet processor. 21 * Abstraction of an inbound packet processor.
20 */ 22 */
...@@ -27,47 +29,48 @@ public interface PacketProcessor { ...@@ -27,47 +29,48 @@ public interface PacketProcessor {
27 /** 29 /**
28 * Returns a priority in the ADVISOR range, where processors can take early action and 30 * 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()). 31 * influence the packet context. However, they cannot handle the packet (i.e. call send() or block()).
32 + * The valid range is from 1 to ADVISOR_MAX.
30 * Processors in this range get to see the packet first. 33 * Processors in this range get to see the packet first.
31 * 34 *
32 * @param priority priority within ADVISOR range 35 * @param priority priority within ADVISOR range
33 * @return overall priority 36 * @return overall priority
34 */ 37 */
35 static int advisor(int priority) { 38 static int advisor(int priority) {
36 - if (priority > 0 && priority <= ADVISOR_MAX) { 39 + int overallPriority = priority + 1;
37 - return priority; 40 + checkArgument(overallPriority > 0 && overallPriority <= ADVISOR_MAX,
38 - } 41 + "Priority not within ADVISOR range");
39 - return ADVISOR_MAX; 42 + return overallPriority;
40 } 43 }
41 44
42 /** 45 /**
43 * Returns a priority in the DIRECTOR range, where processors can handle the packet. 46 * Returns a priority in the DIRECTOR range, where processors can handle the packet.
47 + * The valid range is from ADVISOR_MAX+1 to DIRECTOR_MAX.
44 * Processors in this range get to see the packet second, after ADVISORS. 48 * Processors in this range get to see the packet second, after ADVISORS.
45 * 49 *
46 * @param priority priority within the DIRECTOR range 50 * @param priority priority within the DIRECTOR range
47 * @return overall priority 51 * @return overall priority
48 */ 52 */
49 static int director(int priority) { 53 static int director(int priority) {
50 - int overallPriority = ADVISOR_MAX + priority; 54 + int overallPriority = ADVISOR_MAX + priority + 1;
51 - if (overallPriority > ADVISOR_MAX && overallPriority <= DIRECTOR_MAX) { 55 + checkArgument(overallPriority > ADVISOR_MAX && overallPriority <= DIRECTOR_MAX,
52 - return overallPriority; 56 + "Priority not within DIRECTOR range");
53 - } 57 + return overallPriority;
54 - return DIRECTOR_MAX;
55 } 58 }
56 59
57 /** 60 /**
58 * Returns a priority in the OBSERVER range, where processors cannot take any action, 61 * Returns a priority in the OBSERVER range, where processors cannot take any action,
59 * but can observe what action has been taken until then. 62 * but can observe what action has been taken until then.
63 + * The valid range is from DIRECTOR_MAX+1 to OBSERVER_MAX.
60 * Processors in this range get to see the packet last, after ADVISORS and DIRECTORS. 64 * Processors in this range get to see the packet last, after ADVISORS and DIRECTORS.
61 * 65 *
62 * @param priority priority within the OBSERVER range 66 * @param priority priority within the OBSERVER range
63 * @return overall priority 67 * @return overall priority
64 */ 68 */
65 static int observer(int priority) { 69 static int observer(int priority) {
66 - int overallPriority = DIRECTOR_MAX + priority; 70 + int overallPriority = DIRECTOR_MAX + priority + 1;
67 - if (overallPriority > DIRECTOR_MAX && overallPriority <= OBSERVER_MAX) { 71 + checkArgument(overallPriority > DIRECTOR_MAX && overallPriority <= OBSERVER_MAX,
68 - return overallPriority; 72 + "Priority not within OBSERVER range");
69 - } 73 + return overallPriority;
70 - return OBSERVER_MAX;
71 } 74 }
72 75
73 /** 76 /**
......