Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 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 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 19 | import org.onosproject.openflow.controller.Dpid; |
| 20 | import org.onosproject.openflow.controller.RoleState; |
| 21 | import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch; |
| 22 | import org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver; |
| 23 | import org.onosproject.openflow.controller.driver.OpenFlowSwitchDriverFactory; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 24 | import org.projectfloodlight.openflow.protocol.OFDescStatsReply; |
Jonathan Hart | 2ffcd10 | 2015-01-16 16:47:50 -0800 | [diff] [blame] | 25 | import org.projectfloodlight.openflow.protocol.OFFlowAdd; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 26 | import org.projectfloodlight.openflow.protocol.OFMessage; |
| 27 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
| 28 | import org.projectfloodlight.openflow.protocol.OFVersion; |
Saurav Das | fa2fa93 | 2015-03-03 11:29:48 -0800 | [diff] [blame] | 29 | import org.projectfloodlight.openflow.types.TableId; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 30 | import org.slf4j.Logger; |
| 31 | import org.slf4j.LoggerFactory; |
| 32 | |
Jonathan Hart | bbd91d4 | 2015-02-27 11:18:04 -0800 | [diff] [blame] | 33 | import java.util.Collections; |
| 34 | import java.util.List; |
| 35 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 36 | /** |
| 37 | * A simple implementation of a driver manager that differentiates between |
| 38 | * connected switches using the OF Description Statistics Reply message. |
| 39 | */ |
| 40 | public final class DriverManager implements OpenFlowSwitchDriverFactory { |
| 41 | |
| 42 | private static final Logger log = LoggerFactory.getLogger(DriverManager.class); |
| 43 | |
Jonathan Hart | 2ffcd10 | 2015-01-16 16:47:50 -0800 | [diff] [blame] | 44 | private static final int LOWEST_PRIORITY = 0; |
| 45 | |
Jonathan Hart | bbd91d4 | 2015-02-27 11:18:04 -0800 | [diff] [blame] | 46 | private static Dpid corsaDpid = new Dpid(); |
| 47 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 48 | /** |
| 49 | * Return an IOFSwitch object based on switch's manufacturer description |
| 50 | * from OFDescStatsReply. |
| 51 | * |
| 52 | * @param desc DescriptionStatistics reply from the switch |
| 53 | * @return A IOFSwitch instance if the driver found an implementation for |
| 54 | * the given description. Otherwise it returns OFSwitchImplBase |
| 55 | */ |
| 56 | @Override |
| 57 | public OpenFlowSwitchDriver getOFSwitchImpl(Dpid dpid, |
| 58 | OFDescStatsReply desc, OFVersion ofv) { |
| 59 | String vendor = desc.getMfrDesc(); |
| 60 | String hw = desc.getHwDesc(); |
Jonathan Hart | bbd91d4 | 2015-02-27 11:18:04 -0800 | [diff] [blame] | 61 | |
| 62 | if (dpid.equals(corsaDpid)) { |
sangho | c0b3c34 | 2015-03-12 17:12:10 -0700 | [diff] [blame] | 63 | if (hw.startsWith("Open vSwitch")) { |
| 64 | return new OFOVSSwitchCorsaTTP(dpid, desc); |
| 65 | } else { |
| 66 | return new OFCorsaSwitchDriver(dpid, desc); |
| 67 | } |
Jonathan Hart | bbd91d4 | 2015-02-27 11:18:04 -0800 | [diff] [blame] | 68 | } |
| 69 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 70 | if (vendor.startsWith("Stanford University, Ericsson Research and CPqD Research") |
| 71 | && |
| 72 | hw.startsWith("OpenFlow 1.3 Reference Userspace Switch")) { |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 73 | return new OFSwitchImplSpringOpenTTP(dpid, desc); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 74 | } |
| 75 | |
Jonathan Hart | 081e737 | 2015-01-08 14:17:28 -0800 | [diff] [blame] | 76 | if (hw.startsWith("Open vSwitch")) { |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 77 | if (ofv == OFVersion.OF_10) { |
| 78 | return new OFSwitchImplOVS10(dpid, desc); |
| 79 | } else if (ofv == OFVersion.OF_13) { |
| 80 | return new OFSwitchImplOVS13(dpid, desc); |
| 81 | } |
| 82 | } |
| 83 | |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 84 | String sw = desc.getSwDesc(); |
| 85 | if (sw.startsWith("LINC-OE")) { |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 86 | log.warn("Optical Emulator LINC-OE with DPID:{} found..", dpid); |
Yuta HIGUCHI | bccb6be | 2014-10-09 17:20:29 -0700 | [diff] [blame] | 87 | return new OFOpticalSwitchImplLINC13(dpid, desc); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 88 | } |
| 89 | |
alshabib | 2216bdb | 2015-03-04 16:59:22 -0800 | [diff] [blame] | 90 | if (vendor.startsWith("Corsa") && hw.startsWith("Corsa Element") |
| 91 | && sw.startsWith("2.3.1")) { |
| 92 | log.warn("Corsa Switch 2.3.1 found"); |
| 93 | return new OFCorsaSwitchDriver(dpid, desc); |
| 94 | } |
| 95 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 96 | log.warn("DriverManager could not identify switch desc: {}. " |
Jonathan Hart | bbd91d4 | 2015-02-27 11:18:04 -0800 | [diff] [blame] | 97 | + "Assigning AbstractOpenFlowSwich", desc); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 98 | return new AbstractOpenFlowSwitch(dpid, desc) { |
| 99 | |
| 100 | @Override |
alshabib | 6eb438a | 2014-10-01 16:39:37 -0700 | [diff] [blame] | 101 | public void setRole(RoleState state) { |
| 102 | this.role = RoleState.MASTER; |
| 103 | } |
| 104 | |
| 105 | @Override |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 106 | public void write(List<OFMessage> msgs) { |
| 107 | channel.write(msgs); |
| 108 | } |
| 109 | |
| 110 | @Override |
| 111 | public void write(OFMessage msg) { |
| 112 | channel.write(Collections.singletonList(msg)); |
| 113 | |
| 114 | } |
| 115 | |
| 116 | @Override |
| 117 | public Boolean supportNxRole() { |
| 118 | return false; |
| 119 | } |
| 120 | |
| 121 | @Override |
Jonathan Hart | 2ffcd10 | 2015-01-16 16:47:50 -0800 | [diff] [blame] | 122 | public void startDriverHandshake() { |
| 123 | if (factory().getVersion() == OFVersion.OF_10) { |
| 124 | OFFlowAdd.Builder fmBuilder = factory().buildFlowAdd(); |
| 125 | fmBuilder.setPriority(LOWEST_PRIORITY); |
| 126 | write(fmBuilder.build()); |
| 127 | } |
| 128 | } |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 129 | |
| 130 | @Override |
| 131 | public void processDriverHandshakeMessage(OFMessage m) {} |
| 132 | |
| 133 | @Override |
| 134 | public boolean isDriverHandshakeComplete() { |
| 135 | return true; |
| 136 | } |
| 137 | |
| 138 | @Override |
| 139 | public List<OFPortDesc> getPorts() { |
| 140 | if (this.factory().getVersion() == OFVersion.OF_10) { |
| 141 | return Collections.unmodifiableList(features.getPorts()); |
| 142 | } else { |
| 143 | return Collections.unmodifiableList(ports.getEntries()); |
| 144 | } |
| 145 | } |
Saurav Das | fa2fa93 | 2015-03-03 11:29:48 -0800 | [diff] [blame] | 146 | |
| 147 | @Override |
| 148 | public TableType getTableType(TableId tid) { |
| 149 | return TableType.NONE; |
| 150 | } |
| 151 | |
| 152 | @Override |
| 153 | public void transformAndSendMsg(OFMessage msg, TableType tableType) { |
| 154 | // TODO Auto-generated method stub |
| 155 | |
| 156 | } |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 157 | }; |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Private constructor to avoid instantiation. |
| 162 | */ |
| 163 | private DriverManager() { |
| 164 | } |
| 165 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 166 | public static OpenFlowSwitchDriver getSwitch(Dpid dpid, |
| 167 | OFDescStatsReply desc, OFVersion ofv) { |
| 168 | return new DriverManager().getOFSwitchImpl(dpid, desc, ofv); |
| 169 | } |
| 170 | |
Jonathan Hart | bbd91d4 | 2015-02-27 11:18:04 -0800 | [diff] [blame] | 171 | public static void setCorsaDpid(Dpid dpid) { |
| 172 | corsaDpid = dpid; |
| 173 | } |
| 174 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 175 | } |