Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.intent; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 17 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 18 | import org.onosproject.event.AbstractEvent; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 19 | |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 20 | /** |
| 21 | * A class to represent an intent related event. |
| 22 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 23 | public class IntentEvent extends AbstractEvent<IntentEvent.Type, Intent> { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 24 | |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 25 | public enum Type { |
| 26 | /** |
Brian O'Connor | 7a71d5d | 2014-12-02 00:12:27 -0800 | [diff] [blame] | 27 | * Signifies that an intent is to be installed or reinstalled. |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 28 | */ |
Brian O'Connor | 7a71d5d | 2014-12-02 00:12:27 -0800 | [diff] [blame] | 29 | INSTALL_REQ, |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 30 | |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 31 | /** |
| 32 | * Signifies that an intent has been successfully installed. |
| 33 | */ |
| 34 | INSTALLED, |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 35 | |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 36 | /** |
Brian O'Connor | f0c5a05 | 2015-04-27 00:34:53 -0700 | [diff] [blame] | 37 | * Signifies that an intent has failed compilation and that it cannot |
| 38 | * be satisfied by the network at this time. |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 39 | */ |
| 40 | FAILED, |
| 41 | |
| 42 | /** |
Brian O'Connor | 7a71d5d | 2014-12-02 00:12:27 -0800 | [diff] [blame] | 43 | * Signifies that an intent will be withdrawn. |
| 44 | */ |
| 45 | WITHDRAW_REQ, |
| 46 | |
| 47 | /** |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 48 | * Signifies that an intent has been withdrawn from the system. |
| 49 | */ |
Ray Milkey | 8c6d00e | 2015-03-13 14:14:34 -0700 | [diff] [blame] | 50 | WITHDRAWN, |
| 51 | |
| 52 | /** |
Brian O'Connor | f0c5a05 | 2015-04-27 00:34:53 -0700 | [diff] [blame] | 53 | * 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 Milkey | 8c6d00e | 2015-03-13 14:14:34 -0700 | [diff] [blame] | 60 | * Signifies that an intent has been purged from the system. |
| 61 | */ |
| 62 | PURGED |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | /** |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 66 | * Creates an event of a given type and for the specified intent and the |
| 67 | * current time. |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 68 | * |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 69 | * @param type event type |
| 70 | * @param intent subject intent |
| 71 | * @param time time the event created in milliseconds since start of epoch |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 72 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 73 | public IntentEvent(Type type, Intent intent, long time) { |
| 74 | super(type, intent, time); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | /** |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 78 | * Creates an event of a given type and for the specified intent and the |
| 79 | * current time. |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 80 | * |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 81 | * @param type event type |
| 82 | * @param intent subject intent |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 83 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 84 | public IntentEvent(Type type, Intent intent) { |
| 85 | super(type, intent); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Jonathan Hart | 9288836 | 2015-02-13 13:14:59 -0800 | [diff] [blame] | 88 | /** |
| 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'Connor | 03406a4 | 2015-02-03 17:28:57 -0800 | [diff] [blame] | 96 | public static IntentEvent getEvent(IntentData data) { |
| 97 | return getEvent(data.state(), data.intent()); |
| 98 | } |
| 99 | |
Jonathan Hart | 9288836 | 2015-02-13 13:14:59 -0800 | [diff] [blame] | 100 | /** |
| 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 | */ |
alshabib | a9819bf | 2014-11-30 18:15:52 -0800 | [diff] [blame] | 108 | public static IntentEvent getEvent(IntentState state, Intent intent) { |
| 109 | Type type; |
| 110 | switch (state) { |
Brian O'Connor | 7a71d5d | 2014-12-02 00:12:27 -0800 | [diff] [blame] | 111 | case INSTALL_REQ: |
| 112 | type = Type.INSTALL_REQ; |
alshabib | a9819bf | 2014-11-30 18:15:52 -0800 | [diff] [blame] | 113 | break; |
| 114 | case INSTALLED: |
| 115 | type = Type.INSTALLED; |
| 116 | break; |
Brian O'Connor | 7a71d5d | 2014-12-02 00:12:27 -0800 | [diff] [blame] | 117 | case WITHDRAW_REQ: |
| 118 | type = Type.WITHDRAW_REQ; |
| 119 | break; |
alshabib | a9819bf | 2014-11-30 18:15:52 -0800 | [diff] [blame] | 120 | case WITHDRAWN: |
| 121 | type = Type.WITHDRAWN; |
| 122 | break; |
| 123 | case FAILED: |
| 124 | type = Type.FAILED; |
| 125 | break; |
Brian O'Connor | f0c5a05 | 2015-04-27 00:34:53 -0700 | [diff] [blame] | 126 | case CORRUPT: |
| 127 | type = Type.CORRUPT; |
| 128 | break; |
Ray Milkey | 8c6d00e | 2015-03-13 14:14:34 -0700 | [diff] [blame] | 129 | case PURGE_REQ: |
| 130 | type = Type.PURGED; |
| 131 | break; |
alshabib | a9819bf | 2014-11-30 18:15:52 -0800 | [diff] [blame] | 132 | |
Jonathan Hart | 9288836 | 2015-02-13 13:14:59 -0800 | [diff] [blame] | 133 | // fallthrough to default from here |
alshabib | a9819bf | 2014-11-30 18:15:52 -0800 | [diff] [blame] | 134 | case COMPILING: |
| 135 | case INSTALLING: |
| 136 | case RECOMPILING: |
| 137 | case WITHDRAWING: |
| 138 | default: |
Jonathan Hart | 9288836 | 2015-02-13 13:14:59 -0800 | [diff] [blame] | 139 | return null; |
alshabib | a9819bf | 2014-11-30 18:15:52 -0800 | [diff] [blame] | 140 | } |
| 141 | return new IntentEvent(type, intent); |
| 142 | } |
| 143 | |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 144 | } |