Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -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 | 781d18b | 2014-10-27 10:31:25 -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 | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.openflow.controller; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 17 | |
| 18 | import org.projectfloodlight.openflow.protocol.OFMessage; |
| 19 | |
Marc De Leenheer | 8aba62f | 2017-04-25 14:33:37 -0700 | [diff] [blame] | 20 | import java.util.concurrent.CompletableFuture; |
| 21 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 22 | /** |
| 23 | * Abstraction of an OpenFlow controller. Serves as a one stop |
| 24 | * shop for obtaining OpenFlow devices and (un)register listeners |
| 25 | * on OpenFlow events |
| 26 | */ |
| 27 | public interface OpenFlowController { |
| 28 | |
| 29 | /** |
| 30 | * Returns all switches known to this OF controller. |
| 31 | * @return Iterable of dpid elements |
| 32 | */ |
Sho SHIMIZU | 358815c | 2015-05-13 11:25:32 -0700 | [diff] [blame] | 33 | Iterable<OpenFlowSwitch> getSwitches(); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * Returns all master switches known to this OF controller. |
| 37 | * @return Iterable of dpid elements |
| 38 | */ |
Sho SHIMIZU | 358815c | 2015-05-13 11:25:32 -0700 | [diff] [blame] | 39 | Iterable<OpenFlowSwitch> getMasterSwitches(); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * Returns all equal switches known to this OF controller. |
| 43 | * @return Iterable of dpid elements |
| 44 | */ |
Sho SHIMIZU | 358815c | 2015-05-13 11:25:32 -0700 | [diff] [blame] | 45 | Iterable<OpenFlowSwitch> getEqualSwitches(); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 46 | |
| 47 | |
| 48 | /** |
| 49 | * Returns the actual switch for the given Dpid. |
| 50 | * @param dpid the switch to fetch |
| 51 | * @return the interface to this switch |
| 52 | */ |
Sho SHIMIZU | 358815c | 2015-05-13 11:25:32 -0700 | [diff] [blame] | 53 | OpenFlowSwitch getSwitch(Dpid dpid); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 54 | |
| 55 | /** |
| 56 | * Returns the actual master switch for the given Dpid, if one exists. |
| 57 | * @param dpid the switch to fetch |
| 58 | * @return the interface to this switch |
| 59 | */ |
Sho SHIMIZU | 358815c | 2015-05-13 11:25:32 -0700 | [diff] [blame] | 60 | OpenFlowSwitch getMasterSwitch(Dpid dpid); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 61 | |
| 62 | /** |
| 63 | * Returns the actual equal switch for the given Dpid, if one exists. |
| 64 | * @param dpid the switch to fetch |
| 65 | * @return the interface to this switch |
| 66 | */ |
Sho SHIMIZU | 358815c | 2015-05-13 11:25:32 -0700 | [diff] [blame] | 67 | OpenFlowSwitch getEqualSwitch(Dpid dpid); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 68 | |
| 69 | /** |
| 70 | * Register a listener for meta events that occur to OF |
| 71 | * devices. |
| 72 | * @param listener the listener to notify |
| 73 | */ |
Sho SHIMIZU | 358815c | 2015-05-13 11:25:32 -0700 | [diff] [blame] | 74 | void addListener(OpenFlowSwitchListener listener); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 75 | |
| 76 | /** |
| 77 | * Unregister a listener. |
| 78 | * |
| 79 | * @param listener the listener to unregister |
| 80 | */ |
Sho SHIMIZU | 358815c | 2015-05-13 11:25:32 -0700 | [diff] [blame] | 81 | void removeListener(OpenFlowSwitchListener listener); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 82 | |
| 83 | /** |
Jian Li | a78cdb2 | 2016-04-21 13:03:58 -0700 | [diff] [blame] | 84 | * Register a listener for all OF msg types. |
| 85 | * |
| 86 | * @param listener the listener to notify |
| 87 | */ |
| 88 | void addMessageListener(OpenFlowMessageListener listener); |
| 89 | |
| 90 | /** |
| 91 | * Unregister a listener for all OF msg types. |
| 92 | * |
| 93 | * @param listener the listener to notify |
| 94 | */ |
| 95 | void removeMessageListener(OpenFlowMessageListener listener); |
| 96 | |
| 97 | /** |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 98 | * Register a listener for packet events. |
| 99 | * @param priority the importance of this listener, lower values are more important |
| 100 | * @param listener the listener to notify |
| 101 | */ |
Sho SHIMIZU | 358815c | 2015-05-13 11:25:32 -0700 | [diff] [blame] | 102 | void addPacketListener(int priority, PacketListener listener); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 103 | |
| 104 | /** |
| 105 | * Unregister a listener. |
| 106 | * |
| 107 | * @param listener the listener to unregister |
| 108 | */ |
Sho SHIMIZU | 358815c | 2015-05-13 11:25:32 -0700 | [diff] [blame] | 109 | void removePacketListener(PacketListener listener); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 110 | |
| 111 | /** |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 112 | * Register a listener for OF msg events. |
| 113 | * |
| 114 | * @param listener the listener to notify |
| 115 | */ |
Sho SHIMIZU | 358815c | 2015-05-13 11:25:32 -0700 | [diff] [blame] | 116 | void addEventListener(OpenFlowEventListener listener); |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 117 | |
| 118 | /** |
| 119 | * Unregister a listener. |
| 120 | * |
| 121 | * @param listener the listener to unregister |
| 122 | */ |
Sho SHIMIZU | 358815c | 2015-05-13 11:25:32 -0700 | [diff] [blame] | 123 | void removeEventListener(OpenFlowEventListener listener); |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 124 | |
| 125 | /** |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 126 | * Send a message to a particular switch. |
| 127 | * @param dpid the switch to send to. |
| 128 | * @param msg the message to send |
| 129 | */ |
Sho SHIMIZU | 358815c | 2015-05-13 11:25:32 -0700 | [diff] [blame] | 130 | void write(Dpid dpid, OFMessage msg); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 131 | |
| 132 | /** |
Marc De Leenheer | 8aba62f | 2017-04-25 14:33:37 -0700 | [diff] [blame] | 133 | * Send a message to a particular switch and return the future response. |
| 134 | * |
| 135 | * @param dpid the switch to send to |
| 136 | * @param msg the message to send |
| 137 | * @return future for response message |
| 138 | */ |
| 139 | CompletableFuture<OFMessage> writeResponse(Dpid dpid, OFMessage msg); |
| 140 | |
| 141 | /** |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 142 | * Process a message and notify the appropriate listeners. |
| 143 | * |
| 144 | * @param dpid the dpid the message arrived on |
| 145 | * @param msg the message to process. |
| 146 | */ |
Sho SHIMIZU | 358815c | 2015-05-13 11:25:32 -0700 | [diff] [blame] | 147 | void processPacket(Dpid dpid, OFMessage msg); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 148 | |
| 149 | /** |
| 150 | * Sets the role for a given switch. |
| 151 | * @param role the desired role |
| 152 | * @param dpid the switch to set the role for. |
| 153 | */ |
Sho SHIMIZU | 358815c | 2015-05-13 11:25:32 -0700 | [diff] [blame] | 154 | void setRole(Dpid dpid, RoleState role); |
Anton Chigrin | bf14b37 | 2019-01-14 17:29:56 +0200 | [diff] [blame^] | 155 | |
| 156 | /** |
| 157 | * Remove OpenFlow classifier listener from runtime store of classifiers listener. |
| 158 | * |
| 159 | * @param listener the OpenFlow classifier to remove |
| 160 | */ |
| 161 | void removeClassifierListener(OpenFlowClassifierListener listener); |
| 162 | |
| 163 | /** |
| 164 | * Add OpenFlow classifier listener to runtime store of classifiers listener. |
| 165 | * |
| 166 | * @param listener the OpenFlow classifier listener |
| 167 | */ |
| 168 | void addClassifierListener(OpenFlowClassifierListener listener); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 169 | } |