Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.drivermanager; |
| 2 | |
| 3 | import net.floodlightcontroller.core.IOFSwitch; |
| 4 | import net.floodlightcontroller.core.internal.OFSwitchImplBase; |
| 5 | |
| 6 | import org.projectfloodlight.openflow.protocol.OFDescStatsReply; |
| 7 | import org.projectfloodlight.openflow.protocol.OFVersion; |
| 8 | import org.slf4j.Logger; |
| 9 | import org.slf4j.LoggerFactory; |
| 10 | |
| 11 | /** |
| 12 | * A simple implementation of a driver manager that differentiates between |
| 13 | * connected switches using the OF Description Statistics Reply message. |
| 14 | */ |
| 15 | public final class DriverManager { |
| 16 | |
| 17 | private static final Logger log = LoggerFactory.getLogger(DriverManager.class); |
| 18 | |
Jonathan Hart | cb34f38 | 2014-08-12 21:11:03 -0700 | [diff] [blame] | 19 | // Whether to use an OF 1.3 configured TTP, or to use an OF 1.0-style |
| 20 | // single table with packet-ins. |
| 21 | private static boolean cpqdUsePipeline13 = false; |
| 22 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 23 | /** |
| 24 | * Return an IOFSwitch object based on switch's manufacturer description |
| 25 | * from OFDescStatsReply. |
| 26 | * |
| 27 | * @param desc DescriptionStatistics reply from the switch |
| 28 | * @return A IOFSwitch instance if the driver found an implementation for |
| 29 | * the given description. Otherwise it returns OFSwitchImplBase |
| 30 | */ |
| 31 | public static IOFSwitch getOFSwitchImpl(OFDescStatsReply desc, OFVersion ofv) { |
| 32 | String vendor = desc.getMfrDesc(); |
| 33 | String hw = desc.getHwDesc(); |
| 34 | if (vendor.startsWith("Stanford University, Ericsson Research and CPqD Research") |
| 35 | && |
| 36 | hw.startsWith("OpenFlow 1.3 Reference Userspace Switch")) { |
Jonathan Hart | cb34f38 | 2014-08-12 21:11:03 -0700 | [diff] [blame] | 37 | return new OFSwitchImplCPqD13(desc, cpqdUsePipeline13); |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | if (vendor.startsWith("Nicira") && |
| 41 | hw.startsWith("Open vSwitch")) { |
| 42 | if (ofv == OFVersion.OF_10) { |
| 43 | return new OFSwitchImplOVS10(desc); |
| 44 | } else if (ofv == OFVersion.OF_13) { |
| 45 | return new OFSwitchImplOVS13(desc); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | log.warn("DriverManager could not identify switch desc: {}. " |
| 50 | + "Assigning OFSwitchImplBase", desc); |
| 51 | OFSwitchImplBase base = new OFSwitchImplBase(); |
| 52 | base.setSwitchDescription(desc); |
| 53 | // XXX S must set counter here - unidentified switch |
| 54 | return base; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Private constructor to avoid instantiation. |
| 59 | */ |
| 60 | private DriverManager() { |
| 61 | } |
Jonathan Hart | cb34f38 | 2014-08-12 21:11:03 -0700 | [diff] [blame] | 62 | |
| 63 | /** |
| 64 | * Sets the configuration parameter which determines how the CPqD switch |
| 65 | * is set up. If usePipeline13 is true, a 1.3 pipeline will be set up on |
| 66 | * the switch. Otherwise, the switch will be set up in a 1.0 style with |
| 67 | * a single table where missed packets are sent to the controller. |
| 68 | * |
| 69 | * @param usePipeline13 whether to use a 1.3 pipeline or not |
| 70 | */ |
| 71 | public static void setConfigForCpqd(boolean usePipeline13) { |
| 72 | cpqdUsePipeline13 = usePipeline13; |
| 73 | } |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 74 | } |