blob: 1307f4aba674a05a380a6a78b7ad0349931ab346 [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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.openflow.drivers;
tom7ef8ff92014-09-17 13:08:06 -070017
18
Jonathan Hart081e7372015-01-08 14:17:28 -080019import java.util.Collections;
20import java.util.List;
21
Brian O'Connorabafb502014-12-02 22:26:20 -080022import org.onosproject.openflow.controller.Dpid;
23import org.onosproject.openflow.controller.RoleState;
24import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch;
25import org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver;
26import org.onosproject.openflow.controller.driver.OpenFlowSwitchDriverFactory;
tom7ef8ff92014-09-17 13:08:06 -070027import org.projectfloodlight.openflow.protocol.OFDescStatsReply;
Jonathan Hart2ffcd102015-01-16 16:47:50 -080028import org.projectfloodlight.openflow.protocol.OFFlowAdd;
tom7ef8ff92014-09-17 13:08:06 -070029import org.projectfloodlight.openflow.protocol.OFMessage;
30import org.projectfloodlight.openflow.protocol.OFPortDesc;
31import org.projectfloodlight.openflow.protocol.OFVersion;
32import org.slf4j.Logger;
33import org.slf4j.LoggerFactory;
34
35/**
36 * A simple implementation of a driver manager that differentiates between
37 * connected switches using the OF Description Statistics Reply message.
38 */
39public final class DriverManager implements OpenFlowSwitchDriverFactory {
40
41 private static final Logger log = LoggerFactory.getLogger(DriverManager.class);
42
Jonathan Hart2ffcd102015-01-16 16:47:50 -080043 private static final int LOWEST_PRIORITY = 0;
44
tom7ef8ff92014-09-17 13:08:06 -070045 /**
46 * Return an IOFSwitch object based on switch's manufacturer description
47 * from OFDescStatsReply.
48 *
49 * @param desc DescriptionStatistics reply from the switch
50 * @return A IOFSwitch instance if the driver found an implementation for
51 * the given description. Otherwise it returns OFSwitchImplBase
52 */
53 @Override
54 public OpenFlowSwitchDriver getOFSwitchImpl(Dpid dpid,
55 OFDescStatsReply desc, OFVersion ofv) {
56 String vendor = desc.getMfrDesc();
57 String hw = desc.getHwDesc();
58 if (vendor.startsWith("Stanford University, Ericsson Research and CPqD Research")
59 &&
60 hw.startsWith("OpenFlow 1.3 Reference Userspace Switch")) {
Jonathan Hart47f2dde2015-01-14 17:45:06 -080061 return new OFSwitchImplCPqD13(dpid, desc);
tom7ef8ff92014-09-17 13:08:06 -070062 }
63
Jonathan Hart081e7372015-01-08 14:17:28 -080064 if (hw.startsWith("Open vSwitch")) {
tom7ef8ff92014-09-17 13:08:06 -070065 if (ofv == OFVersion.OF_10) {
66 return new OFSwitchImplOVS10(dpid, desc);
67 } else if (ofv == OFVersion.OF_13) {
68 return new OFSwitchImplOVS13(dpid, desc);
69 }
70 }
71
Praseed Balakrishnane48aa682014-10-08 17:31:37 -070072 String sw = desc.getSwDesc();
73 if (sw.startsWith("LINC-OE")) {
Praseed Balakrishnana22eadf2014-10-20 14:21:45 -070074 log.warn("Optical Emulator LINC-OE with DPID:{} found..", dpid);
Yuta HIGUCHIbccb6be2014-10-09 17:20:29 -070075 return new OFOpticalSwitchImplLINC13(dpid, desc);
Praseed Balakrishnane48aa682014-10-08 17:31:37 -070076 }
77
tom7ef8ff92014-09-17 13:08:06 -070078 log.warn("DriverManager could not identify switch desc: {}. "
79 + "Assigning AbstractOpenFlowSwich", desc);
80 return new AbstractOpenFlowSwitch(dpid, desc) {
81
82 @Override
alshabib6eb438a2014-10-01 16:39:37 -070083 public void setRole(RoleState state) {
84 this.role = RoleState.MASTER;
85 }
86
87 @Override
tom7ef8ff92014-09-17 13:08:06 -070088 public void write(List<OFMessage> msgs) {
89 channel.write(msgs);
90 }
91
92 @Override
93 public void write(OFMessage msg) {
94 channel.write(Collections.singletonList(msg));
95
96 }
97
98 @Override
99 public Boolean supportNxRole() {
100 return false;
101 }
102
103 @Override
Jonathan Hart2ffcd102015-01-16 16:47:50 -0800104 public void startDriverHandshake() {
105 if (factory().getVersion() == OFVersion.OF_10) {
106 OFFlowAdd.Builder fmBuilder = factory().buildFlowAdd();
107 fmBuilder.setPriority(LOWEST_PRIORITY);
108 write(fmBuilder.build());
109 }
110 }
tom7ef8ff92014-09-17 13:08:06 -0700111
112 @Override
113 public void processDriverHandshakeMessage(OFMessage m) {}
114
115 @Override
116 public boolean isDriverHandshakeComplete() {
117 return true;
118 }
119
120 @Override
121 public List<OFPortDesc> getPorts() {
122 if (this.factory().getVersion() == OFVersion.OF_10) {
123 return Collections.unmodifiableList(features.getPorts());
124 } else {
125 return Collections.unmodifiableList(ports.getEntries());
126 }
127 }
128 };
129 }
130
131 /**
132 * Private constructor to avoid instantiation.
133 */
134 private DriverManager() {
135 }
136
tom7ef8ff92014-09-17 13:08:06 -0700137 public static OpenFlowSwitchDriver getSwitch(Dpid dpid,
138 OFDescStatsReply desc, OFVersion ofv) {
139 return new DriverManager().getOFSwitchImpl(dpid, desc, ofv);
140 }
141
142}