blob: 69c305e6d1706ee1a41765b26e784d5a2f1dd48b [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
tom9c94c5b2014-09-17 13:14:42 -070019package org.onlab.onos.openflow.controller.driver;
tom7ef8ff92014-09-17 13:08:06 -070020
21import java.io.IOException;
22
tom9c94c5b2014-09-17 13:14:42 -070023import org.onlab.onos.openflow.controller.RoleState;
tom7ef8ff92014-09-17 13:08:06 -070024import org.projectfloodlight.openflow.protocol.OFErrorMsg;
25import org.projectfloodlight.openflow.protocol.OFExperimenter;
26import org.projectfloodlight.openflow.protocol.OFRoleReply;
27
28/**
29 * Role handling.
30 *
31 */
32public interface RoleHandler {
33
34 /**
35 * Extract the role from an OFVendor message.
36 *
37 * Extract the role from an OFVendor message if the message is a
38 * Nicira role reply. Otherwise return null.
39 *
40 * @param experimenterMsg The vendor message to parse.
41 * @return The role in the message if the message is a Nicira role
42 * reply, null otherwise.
43 * @throws SwitchStateException If the message is a Nicira role reply
44 * but the numeric role value is unknown.
45 */
46 public RoleState extractNiciraRoleReply(OFExperimenter experimenterMsg)
47 throws SwitchStateException;
48
49 /**
50 * Send a role request with the given role to the switch and update
51 * the pending request and timestamp.
52 * Sends an OFPT_ROLE_REQUEST to an OF1.3 switch, OR
53 * Sends an NX_ROLE_REQUEST to an OF1.0 switch if configured to support it
54 * in the IOFSwitch driver. If not supported, this method sends nothing
55 * and returns 'false'. The caller should take appropriate action.
56 *
57 * One other optimization we do here is that for OF1.0 switches with
58 * Nicira role message support, we force the Role.EQUAL to become
59 * Role.SLAVE, as there is no defined behavior for the Nicira role OTHER.
60 * We cannot expect it to behave like SLAVE. We don't have this problem with
61 * OF1.3 switches, because Role.EQUAL is well defined and we can simulate
62 * SLAVE behavior by using ASYNC messages.
63 *
64 * @param role
65 * @throws IOException
66 * @return false if and only if the switch does not support role-request
67 * messages, according to the switch driver; true otherwise.
68 */
69 public boolean sendRoleRequest(RoleState role, RoleRecvStatus exp)
70 throws IOException;
71
72 /**
73 * Extract the role information from an OF1.3 Role Reply Message.
74 * @param rrmsg role reply message
75 * @return RoleReplyInfo object
76 * @throws SwitchStateException
77 */
78 public RoleReplyInfo extractOFRoleReply(OFRoleReply rrmsg)
79 throws SwitchStateException;
80
81 /**
82 * Deliver a received role reply.
83 *
84 * Check if a request is pending and if the received reply matches the
85 * the expected pending reply (we check both role and xid) we set
86 * the role for the switch/channel.
87 *
88 * If a request is pending but doesn't match the reply we ignore it, and
89 * return
90 *
91 * If no request is pending we disconnect with a SwitchStateException
92 *
93 * @param rri information about role-reply in format that
94 * controller can understand.
95 * @throws SwitchStateException if no request is pending
96 */
97 public RoleRecvStatus deliverRoleReply(RoleReplyInfo rri)
98 throws SwitchStateException;
99
100
101 /**
102 * Called if we receive an error message. If the xid matches the
103 * pending request we handle it otherwise we ignore it.
104 *
105 * Note: since we only keep the last pending request we might get
106 * error messages for earlier role requests that we won't be able
107 * to handle
108 */
109 public RoleRecvStatus deliverError(OFErrorMsg error)
110 throws SwitchStateException;
111
112}