blob: 369636aeefbc51cfda4bfdf7fc8a8f84ff9ca3c5 [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'Connorabafb502014-12-02 22:26:20 -080018import org.onosproject.event.AbstractEvent;
Brian O'Connorb876bf12014-10-02 14:59:37 -070019
Brian O'Connorb876bf12014-10-02 14:59:37 -070020/**
21 * A class to represent an intent related event.
22 */
tom85258ee2014-10-07 00:10:02 -070023public class IntentEvent extends AbstractEvent<IntentEvent.Type, Intent> {
Brian O'Connorb876bf12014-10-02 14:59:37 -070024
tom85258ee2014-10-07 00:10:02 -070025 public enum Type {
26 /**
Brian O'Connor7a71d5d2014-12-02 00:12:27 -080027 * Signifies that an intent is to be installed or reinstalled.
tom85258ee2014-10-07 00:10:02 -070028 */
Brian O'Connor7a71d5d2014-12-02 00:12:27 -080029 INSTALL_REQ,
Brian O'Connorb876bf12014-10-02 14:59:37 -070030
tom85258ee2014-10-07 00:10:02 -070031 /**
32 * Signifies that an intent has been successfully installed.
33 */
34 INSTALLED,
Brian O'Connorb876bf12014-10-02 14:59:37 -070035
tom85258ee2014-10-07 00:10:02 -070036 /**
Brian O'Connorf0c5a052015-04-27 00:34:53 -070037 * Signifies that an intent has failed compilation and that it cannot
38 * be satisfied by the network at this time.
tom85258ee2014-10-07 00:10:02 -070039 */
40 FAILED,
41
42 /**
Brian O'Connor7a71d5d2014-12-02 00:12:27 -080043 * Signifies that an intent will be withdrawn.
44 */
45 WITHDRAW_REQ,
46
47 /**
tom85258ee2014-10-07 00:10:02 -070048 * Signifies that an intent has been withdrawn from the system.
49 */
Ray Milkey8c6d00e2015-03-13 14:14:34 -070050 WITHDRAWN,
51
52 /**
Brian O'Connorf0c5a052015-04-27 00:34:53 -070053 * Signifies that an intent has failed installation or withdrawal, but
54 * still hold some or all of its resources.
55 * (e.g. link reservations, flow rules on the data plane, etc.)
56 */
57 CORRUPT,
58
59 /**
Ray Milkey8c6d00e2015-03-13 14:14:34 -070060 * Signifies that an intent has been purged from the system.
61 */
62 PURGED
Brian O'Connorb876bf12014-10-02 14:59:37 -070063 }
64
65 /**
tom85258ee2014-10-07 00:10:02 -070066 * Creates an event of a given type and for the specified intent and the
67 * current time.
Brian O'Connorb876bf12014-10-02 14:59:37 -070068 *
tom85258ee2014-10-07 00:10:02 -070069 * @param type event type
70 * @param intent subject intent
71 * @param time time the event created in milliseconds since start of epoch
Brian O'Connorb876bf12014-10-02 14:59:37 -070072 */
tom85258ee2014-10-07 00:10:02 -070073 public IntentEvent(Type type, Intent intent, long time) {
74 super(type, intent, time);
Brian O'Connorb876bf12014-10-02 14:59:37 -070075 }
76
77 /**
tom85258ee2014-10-07 00:10:02 -070078 * Creates an event of a given type and for the specified intent and the
79 * current time.
Brian O'Connorb876bf12014-10-02 14:59:37 -070080 *
tom85258ee2014-10-07 00:10:02 -070081 * @param type event type
82 * @param intent subject intent
Brian O'Connorb876bf12014-10-02 14:59:37 -070083 */
tom85258ee2014-10-07 00:10:02 -070084 public IntentEvent(Type type, Intent intent) {
85 super(type, intent);
Brian O'Connorb876bf12014-10-02 14:59:37 -070086 }
87
Jonathan Hart92888362015-02-13 13:14:59 -080088 /**
89 * Creates an IntentEvent based on the state contained in the given intent
90 * data. Some states are not sent as external events, and these states will
91 * return null events.
92 *
93 * @param data the intent data to create an event for
94 * @return new intent event if the state is valid, otherwise null.
95 */
Brian O'Connor03406a42015-02-03 17:28:57 -080096 public static IntentEvent getEvent(IntentData data) {
97 return getEvent(data.state(), data.intent());
98 }
99
Jonathan Hart92888362015-02-13 13:14:59 -0800100 /**
101 * Creates an IntentEvent based on the given state and intent. Some states
102 * are not sent as external events, and these states will return null events.
103 *
104 * @param state new state of the intent
105 * @param intent intent to put in event
106 * @return new intent event if the state is valid, otherwise null.
107 */
alshabiba9819bf2014-11-30 18:15:52 -0800108 public static IntentEvent getEvent(IntentState state, Intent intent) {
109 Type type;
110 switch (state) {
Brian O'Connor7a71d5d2014-12-02 00:12:27 -0800111 case INSTALL_REQ:
112 type = Type.INSTALL_REQ;
alshabiba9819bf2014-11-30 18:15:52 -0800113 break;
114 case INSTALLED:
115 type = Type.INSTALLED;
116 break;
Brian O'Connor7a71d5d2014-12-02 00:12:27 -0800117 case WITHDRAW_REQ:
118 type = Type.WITHDRAW_REQ;
119 break;
alshabiba9819bf2014-11-30 18:15:52 -0800120 case WITHDRAWN:
121 type = Type.WITHDRAWN;
122 break;
123 case FAILED:
124 type = Type.FAILED;
125 break;
Brian O'Connorf0c5a052015-04-27 00:34:53 -0700126 case CORRUPT:
127 type = Type.CORRUPT;
128 break;
Ray Milkey8c6d00e2015-03-13 14:14:34 -0700129 case PURGE_REQ:
130 type = Type.PURGED;
131 break;
alshabiba9819bf2014-11-30 18:15:52 -0800132
Jonathan Hart92888362015-02-13 13:14:59 -0800133 // fallthrough to default from here
alshabiba9819bf2014-11-30 18:15:52 -0800134 case COMPILING:
135 case INSTALLING:
136 case RECOMPILING:
137 case WITHDRAWING:
138 default:
Jonathan Hart92888362015-02-13 13:14:59 -0800139 return null;
alshabiba9819bf2014-11-30 18:15:52 -0800140 }
141 return new IntentEvent(type, intent);
142 }
143
Brian O'Connorb876bf12014-10-02 14:59:37 -0700144}