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 | |
Jonathan Hart | 2c44a64 | 2014-08-19 03:40:43 -0700 | [diff] [blame] | 23 | // This flag can be set to prevent the driver manager from classifying |
| 24 | // switches as OVS switches (and thereby the default switch implementation |
| 25 | // will be used). |
| 26 | private static boolean disableOvsClassification = false; |
| 27 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 28 | /** |
| 29 | * Return an IOFSwitch object based on switch's manufacturer description |
| 30 | * from OFDescStatsReply. |
| 31 | * |
| 32 | * @param desc DescriptionStatistics reply from the switch |
| 33 | * @return A IOFSwitch instance if the driver found an implementation for |
| 34 | * the given description. Otherwise it returns OFSwitchImplBase |
| 35 | */ |
| 36 | public static IOFSwitch getOFSwitchImpl(OFDescStatsReply desc, OFVersion ofv) { |
| 37 | String vendor = desc.getMfrDesc(); |
| 38 | String hw = desc.getHwDesc(); |
| 39 | if (vendor.startsWith("Stanford University, Ericsson Research and CPqD Research") |
| 40 | && |
| 41 | hw.startsWith("OpenFlow 1.3 Reference Userspace Switch")) { |
Jonathan Hart | cb34f38 | 2014-08-12 21:11:03 -0700 | [diff] [blame] | 42 | return new OFSwitchImplCPqD13(desc, cpqdUsePipeline13); |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 43 | } |
| 44 | |
Jonathan Hart | 2c44a64 | 2014-08-19 03:40:43 -0700 | [diff] [blame] | 45 | if (!disableOvsClassification && vendor.startsWith("Nicira") && |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 46 | hw.startsWith("Open vSwitch")) { |
| 47 | if (ofv == OFVersion.OF_10) { |
| 48 | return new OFSwitchImplOVS10(desc); |
| 49 | } else if (ofv == OFVersion.OF_13) { |
| 50 | return new OFSwitchImplOVS13(desc); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | log.warn("DriverManager could not identify switch desc: {}. " |
| 55 | + "Assigning OFSwitchImplBase", desc); |
| 56 | OFSwitchImplBase base = new OFSwitchImplBase(); |
| 57 | base.setSwitchDescription(desc); |
| 58 | // XXX S must set counter here - unidentified switch |
| 59 | return base; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Private constructor to avoid instantiation. |
| 64 | */ |
| 65 | private DriverManager() { |
| 66 | } |
Jonathan Hart | cb34f38 | 2014-08-12 21:11:03 -0700 | [diff] [blame] | 67 | |
| 68 | /** |
| 69 | * Sets the configuration parameter which determines how the CPqD switch |
| 70 | * is set up. If usePipeline13 is true, a 1.3 pipeline will be set up on |
| 71 | * the switch. Otherwise, the switch will be set up in a 1.0 style with |
| 72 | * a single table where missed packets are sent to the controller. |
| 73 | * |
| 74 | * @param usePipeline13 whether to use a 1.3 pipeline or not |
| 75 | */ |
| 76 | public static void setConfigForCpqd(boolean usePipeline13) { |
| 77 | cpqdUsePipeline13 = usePipeline13; |
| 78 | } |
Jonathan Hart | 2c44a64 | 2014-08-19 03:40:43 -0700 | [diff] [blame] | 79 | |
| 80 | /** |
| 81 | * Sets the configuration parameter which determines whether switches can |
| 82 | * be classified as OVS switches or as the default switch implementation. |
| 83 | * |
| 84 | * Our use case for this is when running OVS under the Flow Space Firewall |
| 85 | * (FSFW). The FSFW relays the switch desc reply (containing OVS |
| 86 | * description) from the switch to the controller. This causes us to |
| 87 | * classify the fake FSFW switch as OVS, however the FSFW switch doesn't |
| 88 | * support Nicira role requests and it breaks if we try to send them. |
| 89 | * Our workaround is to disable classifying switches as OVS. |
| 90 | * |
| 91 | * @param disableOvsClassificationFlag whether to use OVS switches or not |
| 92 | */ |
| 93 | public static void setDisableOvsClassification( |
| 94 | boolean disableOvsClassificationFlag) { |
| 95 | disableOvsClassification = disableOvsClassificationFlag; |
| 96 | } |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 97 | } |