Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -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 | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 3 | * |
| 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'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.flow; |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -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 | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 19 | import org.onosproject.net.DeviceId; |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 20 | |
| 21 | /** |
| 22 | * Describes flow rule batch event. |
| 23 | */ |
| 24 | public final class FlowRuleBatchEvent extends AbstractEvent<FlowRuleBatchEvent.Type, FlowRuleBatchRequest> { |
| 25 | |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 26 | |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 27 | /** |
| 28 | * Type of flow rule events. |
| 29 | */ |
| 30 | public enum Type { |
| 31 | |
Yuta HIGUCHI | 2fcb40c | 2014-11-03 14:39:10 -0800 | [diff] [blame] | 32 | // Request has been forwarded to MASTER Node |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 33 | /** |
| 34 | * Signifies that a batch operation has been initiated. |
| 35 | */ |
| 36 | BATCH_OPERATION_REQUESTED, |
| 37 | |
Yuta HIGUCHI | 2fcb40c | 2014-11-03 14:39:10 -0800 | [diff] [blame] | 38 | // MASTER Node has pushed the batch down to the Device |
| 39 | // (e.g., Received barrier reply) |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 40 | /** |
| 41 | * Signifies that a batch operation has completed. |
| 42 | */ |
| 43 | BATCH_OPERATION_COMPLETED, |
| 44 | } |
| 45 | |
| 46 | private final CompletedBatchOperation result; |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 47 | private final DeviceId deviceId; |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 48 | |
| 49 | /** |
| 50 | * Constructs a new FlowRuleBatchEvent. |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 51 | * |
| 52 | * @param request batch operation request |
| 53 | * @param deviceId the device this batch will be processed on |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 54 | * @return event. |
| 55 | */ |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 56 | public static FlowRuleBatchEvent requested(FlowRuleBatchRequest request, DeviceId deviceId) { |
| 57 | FlowRuleBatchEvent event = new FlowRuleBatchEvent(Type.BATCH_OPERATION_REQUESTED, request, deviceId); |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 58 | return event; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Constructs a new FlowRuleBatchEvent. |
| 63 | * @param request batch operation request. |
| 64 | * @param result completed batch operation result. |
| 65 | * @return event. |
| 66 | */ |
Yuta HIGUCHI | 9def047 | 2014-10-23 15:51:10 -0700 | [diff] [blame] | 67 | public static FlowRuleBatchEvent completed(FlowRuleBatchRequest request, CompletedBatchOperation result) { |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 68 | FlowRuleBatchEvent event = new FlowRuleBatchEvent(Type.BATCH_OPERATION_COMPLETED, request, result); |
| 69 | return event; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Returns the result of this batch operation. |
| 74 | * @return batch operation result. |
| 75 | */ |
| 76 | public CompletedBatchOperation result() { |
| 77 | return result; |
| 78 | } |
| 79 | |
| 80 | /** |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 81 | * Returns the deviceId for this batch. |
| 82 | * @return device id |
| 83 | */ |
| 84 | public DeviceId deviceId() { |
| 85 | return deviceId; |
| 86 | } |
| 87 | |
| 88 | /** |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 89 | * Creates an event of a given type and for the specified flow rule batch. |
| 90 | * |
| 91 | * @param type flow rule batch event type |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 92 | * @param request event flow rule batch subject |
| 93 | * @param result the result of the batch operation |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 94 | */ |
| 95 | private FlowRuleBatchEvent(Type type, FlowRuleBatchRequest request, CompletedBatchOperation result) { |
| 96 | super(type, request); |
| 97 | this.result = result; |
Brian O'Connor | 72cb19a | 2015-01-16 16:14:41 -0800 | [diff] [blame] | 98 | this.deviceId = result.deviceId(); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Creates an event of a given type and for the specified flow rule batch. |
| 103 | * |
| 104 | * @param type flow rule batch event type |
| 105 | * @param request event flow rule batch subject |
| 106 | * @param deviceId the device id for this batch |
| 107 | */ |
| 108 | private FlowRuleBatchEvent(Type type, FlowRuleBatchRequest request, DeviceId deviceId) { |
| 109 | super(type, request); |
| 110 | this.result = null; |
| 111 | this.deviceId = deviceId; |
Madan Jampani | 117aaae | 2014-10-23 10:04:05 -0700 | [diff] [blame] | 112 | } |
| 113 | } |