blob: b27a5074a19acdc487858f877db51f1fc788209a [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 Open Networking Laboratory
Thomas Vachuska83e090e2014-10-22 14:25:35 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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
Thomas Vachuska83e090e2014-10-22 14:25:35 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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.
Thomas Vachuska83e090e2014-10-22 14:25:35 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.intent;
Brian O'Connorb876bf12014-10-02 14:59:37 -070017
Brian O'Connor9476fa12015-06-25 15:17:17 -040018import com.google.common.annotations.Beta;
Brian O'Connorabafb502014-12-02 22:26:20 -080019import org.onosproject.event.AbstractEvent;
Brian O'Connorb876bf12014-10-02 14:59:37 -070020
Brian O'Connorb876bf12014-10-02 14:59:37 -070021/**
22 * A class to represent an intent related event.
23 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040024@Beta
tom85258ee2014-10-07 00:10:02 -070025public class IntentEvent extends AbstractEvent<IntentEvent.Type, Intent> {
Brian O'Connorb876bf12014-10-02 14:59:37 -070026
tom85258ee2014-10-07 00:10:02 -070027 public enum Type {
28 /**
Brian O'Connor7a71d5d2014-12-02 00:12:27 -080029 * Signifies that an intent is to be installed or reinstalled.
tom85258ee2014-10-07 00:10:02 -070030 */
Brian O'Connor7a71d5d2014-12-02 00:12:27 -080031 INSTALL_REQ,
Brian O'Connorb876bf12014-10-02 14:59:37 -070032
tom85258ee2014-10-07 00:10:02 -070033 /**
34 * Signifies that an intent has been successfully installed.
35 */
36 INSTALLED,
Brian O'Connorb876bf12014-10-02 14:59:37 -070037
tom85258ee2014-10-07 00:10:02 -070038 /**
Brian O'Connorf0c5a052015-04-27 00:34:53 -070039 * Signifies that an intent has failed compilation and that it cannot
40 * be satisfied by the network at this time.
tom85258ee2014-10-07 00:10:02 -070041 */
42 FAILED,
43
44 /**
Brian O'Connor7a71d5d2014-12-02 00:12:27 -080045 * Signifies that an intent will be withdrawn.
46 */
47 WITHDRAW_REQ,
48
49 /**
tom85258ee2014-10-07 00:10:02 -070050 * Signifies that an intent has been withdrawn from the system.
51 */
Ray Milkey8c6d00e2015-03-13 14:14:34 -070052 WITHDRAWN,
53
54 /**
Brian O'Connorf0c5a052015-04-27 00:34:53 -070055 * Signifies that an intent has failed installation or withdrawal, but
56 * still hold some or all of its resources.
57 * (e.g. link reservations, flow rules on the data plane, etc.)
58 */
59 CORRUPT,
60
61 /**
Ray Milkey8c6d00e2015-03-13 14:14:34 -070062 * Signifies that an intent has been purged from the system.
63 */
64 PURGED
Brian O'Connorb876bf12014-10-02 14:59:37 -070065 }
66
67 /**
tom85258ee2014-10-07 00:10:02 -070068 * Creates an event of a given type and for the specified intent and the
69 * current time.
Brian O'Connorb876bf12014-10-02 14:59:37 -070070 *
tom85258ee2014-10-07 00:10:02 -070071 * @param type event type
72 * @param intent subject intent
73 * @param time time the event created in milliseconds since start of epoch
Brian O'Connorb876bf12014-10-02 14:59:37 -070074 */
tom85258ee2014-10-07 00:10:02 -070075 public IntentEvent(Type type, Intent intent, long time) {
76 super(type, intent, time);
Brian O'Connorb876bf12014-10-02 14:59:37 -070077 }
78
79 /**
tom85258ee2014-10-07 00:10:02 -070080 * Creates an event of a given type and for the specified intent and the
81 * current time.
Brian O'Connorb876bf12014-10-02 14:59:37 -070082 *
tom85258ee2014-10-07 00:10:02 -070083 * @param type event type
84 * @param intent subject intent
Brian O'Connorb876bf12014-10-02 14:59:37 -070085 */
tom85258ee2014-10-07 00:10:02 -070086 public IntentEvent(Type type, Intent intent) {
87 super(type, intent);
Brian O'Connorb876bf12014-10-02 14:59:37 -070088 }
89
Jonathan Hart92888362015-02-13 13:14:59 -080090 /**
91 * Creates an IntentEvent based on the state contained in the given intent
92 * data. Some states are not sent as external events, and these states will
93 * return null events.
94 *
95 * @param data the intent data to create an event for
96 * @return new intent event if the state is valid, otherwise null.
97 */
Brian O'Connor03406a42015-02-03 17:28:57 -080098 public static IntentEvent getEvent(IntentData data) {
99 return getEvent(data.state(), data.intent());
100 }
101
Jonathan Hart92888362015-02-13 13:14:59 -0800102 /**
103 * Creates an IntentEvent based on the given state and intent. Some states
104 * are not sent as external events, and these states will return null events.
105 *
106 * @param state new state of the intent
107 * @param intent intent to put in event
108 * @return new intent event if the state is valid, otherwise null.
109 */
alshabiba9819bf2014-11-30 18:15:52 -0800110 public static IntentEvent getEvent(IntentState state, Intent intent) {
111 Type type;
112 switch (state) {
Brian O'Connor7a71d5d2014-12-02 00:12:27 -0800113 case INSTALL_REQ:
114 type = Type.INSTALL_REQ;
alshabiba9819bf2014-11-30 18:15:52 -0800115 break;
116 case INSTALLED:
117 type = Type.INSTALLED;
118 break;
Brian O'Connor7a71d5d2014-12-02 00:12:27 -0800119 case WITHDRAW_REQ:
120 type = Type.WITHDRAW_REQ;
121 break;
alshabiba9819bf2014-11-30 18:15:52 -0800122 case WITHDRAWN:
123 type = Type.WITHDRAWN;
124 break;
125 case FAILED:
126 type = Type.FAILED;
127 break;
Brian O'Connorf0c5a052015-04-27 00:34:53 -0700128 case CORRUPT:
129 type = Type.CORRUPT;
130 break;
Ray Milkey8c6d00e2015-03-13 14:14:34 -0700131 case PURGE_REQ:
132 type = Type.PURGED;
133 break;
alshabiba9819bf2014-11-30 18:15:52 -0800134
Jonathan Hart92888362015-02-13 13:14:59 -0800135 // fallthrough to default from here
alshabiba9819bf2014-11-30 18:15:52 -0800136 case COMPILING:
137 case INSTALLING:
138 case RECOMPILING:
139 case WITHDRAWING:
140 default:
Jonathan Hart92888362015-02-13 13:14:59 -0800141 return null;
alshabiba9819bf2014-11-30 18:15:52 -0800142 }
143 return new IntentEvent(type, intent);
144 }
145
Brian O'Connorb876bf12014-10-02 14:59:37 -0700146}