Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 2 | * Copyright 2014 Open Networking Laboratory |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.openflow.drivers; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 17 | |
| 18 | |
Jonathan Hart | 081e737 | 2015-01-08 14:17:28 -0800 | [diff] [blame] | 19 | import java.util.Collections; |
| 20 | import java.util.List; |
| 21 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 22 | import org.onosproject.openflow.controller.Dpid; |
| 23 | import org.onosproject.openflow.controller.RoleState; |
| 24 | import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch; |
| 25 | import org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver; |
| 26 | import org.onosproject.openflow.controller.driver.OpenFlowSwitchDriverFactory; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 27 | import org.projectfloodlight.openflow.protocol.OFDescStatsReply; |
| 28 | import org.projectfloodlight.openflow.protocol.OFMessage; |
| 29 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
| 30 | import org.projectfloodlight.openflow.protocol.OFVersion; |
| 31 | import org.slf4j.Logger; |
| 32 | import org.slf4j.LoggerFactory; |
| 33 | |
| 34 | /** |
| 35 | * A simple implementation of a driver manager that differentiates between |
| 36 | * connected switches using the OF Description Statistics Reply message. |
| 37 | */ |
| 38 | public final class DriverManager implements OpenFlowSwitchDriverFactory { |
| 39 | |
| 40 | private static final Logger log = LoggerFactory.getLogger(DriverManager.class); |
| 41 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 42 | /** |
| 43 | * Return an IOFSwitch object based on switch's manufacturer description |
| 44 | * from OFDescStatsReply. |
| 45 | * |
| 46 | * @param desc DescriptionStatistics reply from the switch |
| 47 | * @return A IOFSwitch instance if the driver found an implementation for |
| 48 | * the given description. Otherwise it returns OFSwitchImplBase |
| 49 | */ |
| 50 | @Override |
| 51 | public OpenFlowSwitchDriver getOFSwitchImpl(Dpid dpid, |
| 52 | OFDescStatsReply desc, OFVersion ofv) { |
| 53 | String vendor = desc.getMfrDesc(); |
| 54 | String hw = desc.getHwDesc(); |
| 55 | if (vendor.startsWith("Stanford University, Ericsson Research and CPqD Research") |
| 56 | && |
| 57 | hw.startsWith("OpenFlow 1.3 Reference Userspace Switch")) { |
Jonathan Hart | 47f2dde | 2015-01-14 17:45:06 -0800 | [diff] [blame^] | 58 | return new OFSwitchImplCPqD13(dpid, desc); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Jonathan Hart | 081e737 | 2015-01-08 14:17:28 -0800 | [diff] [blame] | 61 | if (hw.startsWith("Open vSwitch")) { |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 62 | if (ofv == OFVersion.OF_10) { |
| 63 | return new OFSwitchImplOVS10(dpid, desc); |
| 64 | } else if (ofv == OFVersion.OF_13) { |
| 65 | return new OFSwitchImplOVS13(dpid, desc); |
| 66 | } |
| 67 | } |
| 68 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 69 | String sw = desc.getSwDesc(); |
| 70 | if (sw.startsWith("LINC-OE")) { |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 71 | log.warn("Optical Emulator LINC-OE with DPID:{} found..", dpid); |
Yuta HIGUCHI | bccb6be | 2014-10-09 17:20:29 -0700 | [diff] [blame] | 72 | return new OFOpticalSwitchImplLINC13(dpid, desc); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 73 | } |
| 74 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 75 | log.warn("DriverManager could not identify switch desc: {}. " |
| 76 | + "Assigning AbstractOpenFlowSwich", desc); |
| 77 | return new AbstractOpenFlowSwitch(dpid, desc) { |
| 78 | |
| 79 | @Override |
alshabib | 6eb438a | 2014-10-01 16:39:37 -0700 | [diff] [blame] | 80 | public void setRole(RoleState state) { |
| 81 | this.role = RoleState.MASTER; |
| 82 | } |
| 83 | |
| 84 | @Override |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 85 | public void write(List<OFMessage> msgs) { |
| 86 | channel.write(msgs); |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public void write(OFMessage msg) { |
| 91 | channel.write(Collections.singletonList(msg)); |
| 92 | |
| 93 | } |
| 94 | |
| 95 | @Override |
| 96 | public Boolean supportNxRole() { |
| 97 | return false; |
| 98 | } |
| 99 | |
| 100 | @Override |
| 101 | public void startDriverHandshake() {} |
| 102 | |
| 103 | @Override |
| 104 | public void processDriverHandshakeMessage(OFMessage m) {} |
| 105 | |
| 106 | @Override |
| 107 | public boolean isDriverHandshakeComplete() { |
| 108 | return true; |
| 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public List<OFPortDesc> getPorts() { |
| 113 | if (this.factory().getVersion() == OFVersion.OF_10) { |
| 114 | return Collections.unmodifiableList(features.getPorts()); |
| 115 | } else { |
| 116 | return Collections.unmodifiableList(ports.getEntries()); |
| 117 | } |
| 118 | } |
| 119 | }; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Private constructor to avoid instantiation. |
| 124 | */ |
| 125 | private DriverManager() { |
| 126 | } |
| 127 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 128 | public static OpenFlowSwitchDriver getSwitch(Dpid dpid, |
| 129 | OFDescStatsReply desc, OFVersion ofv) { |
| 130 | return new DriverManager().getOFSwitchImpl(dpid, desc, ofv); |
| 131 | } |
| 132 | |
| 133 | } |