blob: a18a8cfd25519a1e64f2df08ffcd552e3fbcf4ca [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Thomas Vachuska781d18b2014-10-27 10:31:25 -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 Vachuska781d18b2014-10-27 10:31:25 -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 Vachuska781d18b2014-10-27 10:31:25 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.openflow.controller.driver;
tom7ef8ff92014-09-17 13:08:06 -070017
18import java.io.IOException;
19
Brian O'Connorabafb502014-12-02 22:26:20 -080020import org.onosproject.openflow.controller.RoleState;
tom7ef8ff92014-09-17 13:08:06 -070021import org.projectfloodlight.openflow.protocol.OFErrorMsg;
22import org.projectfloodlight.openflow.protocol.OFExperimenter;
23import org.projectfloodlight.openflow.protocol.OFRoleReply;
24
25/**
26 * Role handling.
27 *
28 */
29public interface RoleHandler {
30
31 /**
32 * Extract the role from an OFVendor message.
33 *
34 * Extract the role from an OFVendor message if the message is a
35 * Nicira role reply. Otherwise return null.
36 *
37 * @param experimenterMsg The vendor message to parse.
38 * @return The role in the message if the message is a Nicira role
39 * reply, null otherwise.
40 * @throws SwitchStateException If the message is a Nicira role reply
41 * but the numeric role value is unknown.
42 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -070043 RoleState extractNiciraRoleReply(OFExperimenter experimenterMsg)
tom7ef8ff92014-09-17 13:08:06 -070044 throws SwitchStateException;
45
46 /**
47 * Send a role request with the given role to the switch and update
48 * the pending request and timestamp.
49 * Sends an OFPT_ROLE_REQUEST to an OF1.3 switch, OR
50 * Sends an NX_ROLE_REQUEST to an OF1.0 switch if configured to support it
51 * in the IOFSwitch driver. If not supported, this method sends nothing
52 * and returns 'false'. The caller should take appropriate action.
53 *
54 * One other optimization we do here is that for OF1.0 switches with
55 * Nicira role message support, we force the Role.EQUAL to become
56 * Role.SLAVE, as there is no defined behavior for the Nicira role OTHER.
57 * We cannot expect it to behave like SLAVE. We don't have this problem with
58 * OF1.3 switches, because Role.EQUAL is well defined and we can simulate
59 * SLAVE behavior by using ASYNC messages.
60 *
Yuta HIGUCHI5c947272014-11-03 21:39:21 -080061 * @param role role to request
62 * @param exp expectation
63 * @throws IOException when I/O exception of some sort has occurred
tom7ef8ff92014-09-17 13:08:06 -070064 * @return false if and only if the switch does not support role-request
65 * messages, according to the switch driver; true otherwise.
66 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -070067 boolean sendRoleRequest(RoleState role, RoleRecvStatus exp)
tom7ef8ff92014-09-17 13:08:06 -070068 throws IOException;
69
70 /**
71 * Extract the role information from an OF1.3 Role Reply Message.
72 * @param rrmsg role reply message
73 * @return RoleReplyInfo object
Yuta HIGUCHI5c947272014-11-03 21:39:21 -080074 * @throws SwitchStateException If unknown role encountered
tom7ef8ff92014-09-17 13:08:06 -070075 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -070076 RoleReplyInfo extractOFRoleReply(OFRoleReply rrmsg)
tom7ef8ff92014-09-17 13:08:06 -070077 throws SwitchStateException;
78
79 /**
80 * Deliver a received role reply.
81 *
82 * Check if a request is pending and if the received reply matches the
83 * the expected pending reply (we check both role and xid) we set
84 * the role for the switch/channel.
85 *
86 * If a request is pending but doesn't match the reply we ignore it, and
87 * return
88 *
89 * If no request is pending we disconnect with a SwitchStateException
90 *
91 * @param rri information about role-reply in format that
92 * controller can understand.
Yuta HIGUCHI5c947272014-11-03 21:39:21 -080093 * @return result comparing expected and received reply
tom7ef8ff92014-09-17 13:08:06 -070094 * @throws SwitchStateException if no request is pending
95 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -070096 RoleRecvStatus deliverRoleReply(RoleReplyInfo rri)
tom7ef8ff92014-09-17 13:08:06 -070097 throws SwitchStateException;
98
99
100 /**
101 * Called if we receive an error message. If the xid matches the
102 * pending request we handle it otherwise we ignore it.
103 *
104 * Note: since we only keep the last pending request we might get
105 * error messages for earlier role requests that we won't be able
106 * to handle
Yuta HIGUCHI5c947272014-11-03 21:39:21 -0800107 * @param error error message
108 * @return result comparing expected and received reply
109 * @throws SwitchStateException if switch did not support requested role
tom7ef8ff92014-09-17 13:08:06 -0700110 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -0700111 RoleRecvStatus deliverError(OFErrorMsg error)
tom7ef8ff92014-09-17 13:08:06 -0700112 throws SwitchStateException;
113
114}