b4068886024676be70e6db556990dd25a88841d7
[onosfw.git] /
1 /*
2  * Copyright 2014 Open Networking Laboratory
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  */
16 package org.onosproject.openflow.controller.driver;
17
18 import java.io.IOException;
19
20 import org.onosproject.openflow.controller.RoleState;
21 import org.projectfloodlight.openflow.protocol.OFErrorMsg;
22 import org.projectfloodlight.openflow.protocol.OFExperimenter;
23 import org.projectfloodlight.openflow.protocol.OFRoleReply;
24
25 /**
26  * Role handling.
27  *
28  */
29 public 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      */
43     RoleState extractNiciraRoleReply(OFExperimenter experimenterMsg)
44             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      *
61      * @param role role to request
62      * @param exp expectation
63      * @throws IOException when I/O exception of some sort has occurred
64      * @return false if and only if the switch does not support role-request
65      * messages, according to the switch driver; true otherwise.
66      */
67     boolean sendRoleRequest(RoleState role, RoleRecvStatus exp)
68             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
74      * @throws SwitchStateException If unknown role encountered
75      */
76     RoleReplyInfo extractOFRoleReply(OFRoleReply rrmsg)
77             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.
93      * @return result comparing expected and received reply
94      * @throws SwitchStateException if no request is pending
95      */
96     RoleRecvStatus deliverRoleReply(RoleReplyInfo rri)
97             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
107      * @param error error message
108      * @return result comparing expected and received reply
109      * @throws SwitchStateException if switch did not support requested role
110      */
111     RoleRecvStatus deliverError(OFErrorMsg error)
112             throws SwitchStateException;
113
114 }