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; |
Jonathan Hart | 2ffcd10 | 2015-01-16 16:47:50 -0800 | [diff] [blame] | 28 | import org.projectfloodlight.openflow.protocol.OFFlowAdd; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 29 | import org.projectfloodlight.openflow.protocol.OFMessage; |
| 30 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
| 31 | import org.projectfloodlight.openflow.protocol.OFVersion; |
| 32 | import org.slf4j.Logger; |
| 33 | import 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 | */ |
| 39 | public final class DriverManager implements OpenFlowSwitchDriverFactory { |
| 40 | |
| 41 | private static final Logger log = LoggerFactory.getLogger(DriverManager.class); |
| 42 | |
Jonathan Hart | 2ffcd10 | 2015-01-16 16:47:50 -0800 | [diff] [blame] | 43 | private static final int LOWEST_PRIORITY = 0; |
| 44 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 45 | /** |
| 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 Hart | 47f2dde | 2015-01-14 17:45:06 -0800 | [diff] [blame] | 61 | return new OFSwitchImplCPqD13(dpid, desc); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Jonathan Hart | 081e737 | 2015-01-08 14:17:28 -0800 | [diff] [blame] | 64 | if (hw.startsWith("Open vSwitch")) { |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 65 | 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 Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 72 | String sw = desc.getSwDesc(); |
| 73 | if (sw.startsWith("LINC-OE")) { |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 74 | log.warn("Optical Emulator LINC-OE with DPID:{} found..", dpid); |
Yuta HIGUCHI | bccb6be | 2014-10-09 17:20:29 -0700 | [diff] [blame] | 75 | return new OFOpticalSwitchImplLINC13(dpid, desc); |
Praseed Balakrishnan | e48aa68 | 2014-10-08 17:31:37 -0700 | [diff] [blame] | 76 | } |
| 77 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 78 | log.warn("DriverManager could not identify switch desc: {}. " |
| 79 | + "Assigning AbstractOpenFlowSwich", desc); |
| 80 | return new AbstractOpenFlowSwitch(dpid, desc) { |
| 81 | |
| 82 | @Override |
alshabib | 6eb438a | 2014-10-01 16:39:37 -0700 | [diff] [blame] | 83 | public void setRole(RoleState state) { |
| 84 | this.role = RoleState.MASTER; |
| 85 | } |
| 86 | |
| 87 | @Override |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 88 | 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 Hart | 2ffcd10 | 2015-01-16 16:47:50 -0800 | [diff] [blame] | 104 | 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 | } |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 111 | |
| 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 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 137 | public static OpenFlowSwitchDriver getSwitch(Dpid dpid, |
| 138 | OFDescStatsReply desc, OFVersion ofv) { |
| 139 | return new DriverManager().getOFSwitchImpl(dpid, desc, ofv); |
| 140 | } |
| 141 | |
| 142 | } |