2  * Copyright 2014 Open Networking Laboratory
 
   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
 
   8  *     http://www.apache.org/licenses/LICENSE-2.0
 
  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.
 
  16 package org.onosproject.openflow.controller.driver;
 
  18 import java.io.IOException;
 
  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;
 
  29 public interface RoleHandler {
 
  32      * Extract the role from an OFVendor message.
 
  34      * Extract the role from an OFVendor message if the message is a
 
  35      * Nicira role reply. Otherwise return null.
 
  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.
 
  43     RoleState extractNiciraRoleReply(OFExperimenter experimenterMsg)
 
  44             throws SwitchStateException;
 
  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.
 
  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.
 
  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.
 
  67     boolean sendRoleRequest(RoleState role, RoleRecvStatus exp)
 
  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
 
  76     RoleReplyInfo extractOFRoleReply(OFRoleReply rrmsg)
 
  77             throws SwitchStateException;
 
  80      * Deliver a received role reply.
 
  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.
 
  86      * If a request is pending but doesn't match the reply we ignore it, and
 
  89      * If no request is pending we disconnect with a SwitchStateException
 
  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
 
  96     RoleRecvStatus deliverRoleReply(RoleReplyInfo rri)
 
  97             throws SwitchStateException;
 
 101      * Called if we receive an  error message. If the xid matches the
 
 102      * pending request we handle it otherwise we ignore it.
 
 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
 
 107      * @param error error message
 
 108      * @return result comparing expected and received reply
 
 109      * @throws SwitchStateException if switch did not support requested role
 
 111     RoleRecvStatus deliverError(OFErrorMsg error)
 
 112             throws SwitchStateException;