blob: 8611664a1f6b55c702d5c269f43cbe3d4f151db8 [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 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 */
tom9c94c5b2014-09-17 13:14:42 -070016package org.onlab.onos.openflow.controller.driver;
tom7ef8ff92014-09-17 13:08:06 -070017
18import java.io.IOException;
19
tom9c94c5b2014-09-17 13:14:42 -070020import org.onlab.onos.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 */
43 public 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
62 * @throws IOException
63 * @return false if and only if the switch does not support role-request
64 * messages, according to the switch driver; true otherwise.
65 */
66 public boolean sendRoleRequest(RoleState role, RoleRecvStatus exp)
67 throws IOException;
68
69 /**
70 * Extract the role information from an OF1.3 Role Reply Message.
71 * @param rrmsg role reply message
72 * @return RoleReplyInfo object
73 * @throws SwitchStateException
74 */
75 public RoleReplyInfo extractOFRoleReply(OFRoleReply rrmsg)
76 throws SwitchStateException;
77
78 /**
79 * Deliver a received role reply.
80 *
81 * Check if a request is pending and if the received reply matches the
82 * the expected pending reply (we check both role and xid) we set
83 * the role for the switch/channel.
84 *
85 * If a request is pending but doesn't match the reply we ignore it, and
86 * return
87 *
88 * If no request is pending we disconnect with a SwitchStateException
89 *
90 * @param rri information about role-reply in format that
91 * controller can understand.
92 * @throws SwitchStateException if no request is pending
93 */
94 public RoleRecvStatus deliverRoleReply(RoleReplyInfo rri)
95 throws SwitchStateException;
96
97
98 /**
99 * Called if we receive an error message. If the xid matches the
100 * pending request we handle it otherwise we ignore it.
101 *
102 * Note: since we only keep the last pending request we might get
103 * error messages for earlier role requests that we won't be able
104 * to handle
105 */
106 public RoleRecvStatus deliverError(OFErrorMsg error)
107 throws SwitchStateException;
108
109}