blob: ad37612f4a55fbb49e2349a4a1a814c18bd0b58a [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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
samanwita pal14150eb2015-07-30 11:27:37 -070018import static com.google.common.base.Preconditions.checkArgument;
19
tom613d8142014-09-11 15:09:37 -070020/**
21 * Abstraction of an inbound packet processor.
22 */
23public interface PacketProcessor {
24
Sho SHIMIZUe2952e42015-09-11 17:11:21 -070025 int ADVISOR_MAX = Integer.MAX_VALUE / 3;
26 int DIRECTOR_MAX = (Integer.MAX_VALUE / 3) * 2;
Thomas Vachuska7f171b22015-08-21 12:49:08 -070027 int OBSERVER_MAX = Integer.MAX_VALUE;
alshabib369d2942014-09-12 17:59:35 -070028
tom613d8142014-09-11 15:09:37 -070029 /**
samanwita palf5286362015-07-29 12:59:00 -070030 * Returns a priority in the ADVISOR range, where processors can take early action and
31 * influence the packet context. However, they cannot handle the packet (i.e. call send() or block()).
samanwita pal14150eb2015-07-30 11:27:37 -070032 * The valid range is from 1 to ADVISOR_MAX.
samanwita palf5286362015-07-29 12:59:00 -070033 * Processors in this range get to see the packet first.
34 *
35 * @param priority priority within ADVISOR range
36 * @return overall priority
37 */
38 static int advisor(int priority) {
samanwita pal14150eb2015-07-30 11:27:37 -070039 int overallPriority = priority + 1;
40 checkArgument(overallPriority > 0 && overallPriority <= ADVISOR_MAX,
Thomas Vachuska7f171b22015-08-21 12:49:08 -070041 "Priority not within ADVISOR range");
samanwita pal14150eb2015-07-30 11:27:37 -070042 return overallPriority;
samanwita palf5286362015-07-29 12:59:00 -070043 }
44
45 /**
46 * Returns a priority in the DIRECTOR range, where processors can handle the packet.
samanwita pal14150eb2015-07-30 11:27:37 -070047 * The valid range is from ADVISOR_MAX+1 to DIRECTOR_MAX.
samanwita palf5286362015-07-29 12:59:00 -070048 * Processors in this range get to see the packet second, after ADVISORS.
49 *
50 * @param priority priority within the DIRECTOR range
51 * @return overall priority
52 */
53 static int director(int priority) {
samanwita pal14150eb2015-07-30 11:27:37 -070054 int overallPriority = ADVISOR_MAX + priority + 1;
55 checkArgument(overallPriority > ADVISOR_MAX && overallPriority <= DIRECTOR_MAX,
Thomas Vachuska7f171b22015-08-21 12:49:08 -070056 "Priority not within DIRECTOR range");
samanwita pal14150eb2015-07-30 11:27:37 -070057 return overallPriority;
samanwita palf5286362015-07-29 12:59:00 -070058 }
59
60 /**
61 * Returns a priority in the OBSERVER range, where processors cannot take any action,
62 * but can observe what action has been taken until then.
samanwita pal14150eb2015-07-30 11:27:37 -070063 * The valid range is from DIRECTOR_MAX+1 to OBSERVER_MAX.
samanwita palf5286362015-07-29 12:59:00 -070064 * Processors in this range get to see the packet last, after ADVISORS and DIRECTORS.
65 *
66 * @param priority priority within the OBSERVER range
67 * @return overall priority
68 */
69 static int observer(int priority) {
samanwita pal14150eb2015-07-30 11:27:37 -070070 int overallPriority = DIRECTOR_MAX + priority + 1;
Thomas Vachuska7f171b22015-08-21 12:49:08 -070071 checkArgument(overallPriority > DIRECTOR_MAX,
72 "Priority not within OBSERVER range");
samanwita pal14150eb2015-07-30 11:27:37 -070073 return overallPriority;
samanwita palf5286362015-07-29 12:59:00 -070074 }
75
76 /**
tom613d8142014-09-11 15:09:37 -070077 * Processes the inbound packet as specified in the given context.
78 *
79 * @param context packet processing context
80 */
81 void process(PacketContext context);
82
83}