Major code change: s/general/access/

Fix misunderstanding from unclear documentation: in Cisco terms, we
want to be using "Access" mode for ports rather than "General"
mode. This simplifies the sX300 driver somewhat (which is good!) and
makes the two drivers more similar in operation.

Testing is good:

 * the built-in test harnesses work ok for driving both models of
   switch
 * single SF-300 shows appropriate VLAN isolation
 * single Catalyst-3750 works similarly
 * cross SF-300 interop works similarly
 * SF-300 to Catalyst-3750 works similarly

Change-Id: I1b89afc4c3504f197a2f8dd819e7c4ee3babfde9
diff --git a/drivers/cisco-sX300.py b/drivers/cisco-sX300.py
index 69cabca..72c7d7d 100644
--- a/drivers/cisco-sX300.py
+++ b/drivers/cisco-sX300.py
@@ -174,7 +174,7 @@
     ### Port API functions
     ################################    
 
-    # Set the mode of a port: general or trunk
+    # Set the mode of a port: access or trunk
     def port_set_mode(self, port, mode):
         logging.debug("Setting port %s to %s" % (port, mode))
         if not self._is_port_mode_valid(mode):
@@ -192,7 +192,7 @@
             raise IOError("Failed to set mode for port %s" % port)
 
 
-    # Get the mode of a port: general or trunk
+    # Get the mode of a port: access or trunk
     def port_get_mode(self, port):
         logging.debug("Getting mode of port %s" % port)
         mode = ''
@@ -206,38 +206,23 @@
                 mode = match.group(1)
         return mode.lower()
 
-    # Set a general port to be in a specified VLAN (tag)
-    def port_set_general_vlan(self, port, tag):
-        logging.debug("Setting general port %s to VLAN %d" % (port, tag))
+    # Set an access port to be in a specified VLAN (tag)
+    def port_set_access_vlan(self, port, tag):
+        logging.debug("Setting access port %s to VLAN %d" % (port, tag))
         if not self._is_port_name_valid(port):
             raise IndexError("Port name %s not recognised" % port)
-        if not (self.port_get_mode(port) == "general"):
-            raise IndexError("Port %s not in general mode" % port)
+        if not (self.port_get_mode(port) == "access"):
+            raise IndexError("Port %s not in access mode" % port)
 
-        # More complicated than just a "set" on the hardware, so let's
-        # split it up into separate helper calls.
+        self._configure()
+        self._cli("interface %s" % port)
+        self._cli("switchport access vlan %d" % tag)
+        self._end_configure()        
 
-        # First, get the current VLAN
-        current_vlan = self.port_get_general_vlan(port)
-
-        # Next, drop off that current VLAN
-        # VLAN 1 is handled specially :-(
-        if current_vlan == 1:
-            self._port_general_block_default_vlan(port)
-        else:
-            self._port_remove_general_from_vlan(port, current_vlan)
-
-        # Next, add the desired VLAN
-        # VLAN 1 is handled specially again :-(
-        if tag == 1:
-            self._port_general_allow_default_vlan(port)
-        else:
-            self._port_add_general_to_vlan(port, tag)
-
-        # Finally, validate things worked
-        read_vlan = int(self.port_get_general_vlan(port))
+        # Validate things worked
+        read_vlan = int(self.port_get_access_vlan(port))
         if read_vlan != tag:
-            raise IOError("Failed to move general port %s to VLAN %d - got VLAN %d instead"
+            raise IOError("Failed to move access port %s to VLAN %d - got VLAN %d instead"
                           % (port, tag, read_vlan))
 
     # Add a trunk port to a specified VLAN (tag)
@@ -277,14 +262,14 @@
             if vlan == tag:
                 raise IOError("Failed to remove trunk port %s from VLAN %d" % (port, tag))
 
-    # Get the configured VLAN tag for an general port (tag)
-    def port_get_general_vlan(self, port):
-        logging.debug("Getting VLAN for general port %s" % port)
+    # Get the configured VLAN tag for an access port (tag)
+    def port_get_access_vlan(self, port):
+        logging.debug("Getting VLAN for access port %s" % port)
         vlan = 1
         if not self._is_port_name_valid(port):
             raise IndexError("Port name %s not recognised" % port)
-        if not (self.port_get_mode(port) == "general"):
-            raise IndexError("Port %s not in general mode" % port)
+        if not (self.port_get_mode(port) == "access"):
+            raise IndexError("Port %s not in access mode" % port)
         regex = re.compile('(\d+)\s+\S+\s+Untagged\s+Static')
         self._cli("show interfaces switchport %s" % port)
         for line in self._read_paged_output():
@@ -300,7 +285,7 @@
         if not self._is_port_name_valid(port):
             raise IndexError("Port name %s not recognised" % port)
         if not (self.port_get_mode(port) == "trunk"):
-            raise IndexError("Port %s not in general mode" % port)
+            raise IndexError("Port %s not in access mode" % port)
         regex = re.compile('(\d+)\s+\S+\s+(Tagged|Untagged)\s+Static')
         self._cli("show interfaces switchport %s" % port)
         for line in self._read_paged_output():
@@ -402,42 +387,6 @@
     # at the higher level.
     ######################################
     
-    # Allow the default VLAN on a port
-    def _port_general_allow_default_vlan(self, port):
-        logging.debug("Allowing default VLAN (1) for general port %s" % port)
-        self._configure()
-        self._cli("interface %s" % port)
-        self._cli("no switchport forbidden default-vlan")
-        self._end_configure()
-        # Difficult to validate
-
-    # Block the default VLAN on a port
-    def _port_general_block_default_vlan(self, port):
-        logging.debug("Blocking default VLAN (1) for general port %s" % port)
-        self._configure()
-        self._cli("interface %s" % port)
-        self._cli("switchport forbidden default-vlan")
-        self._end_configure()        
-        # Difficult to validate
-
-    # Add a general port to a specified VLAN (tag)
-    def _port_add_general_to_vlan(self, port, tag):
-        logging.debug("Adding general port %s to VLAN %d" % (port, tag))
-        self._configure()
-        self._cli("interface %s" % port)
-        self._cli("switchport general pvid %d" % tag)
-        self._cli("switchport general allowed vlan add %d untagged" % tag)
-        self._end_configure()
-
-    # Remove a general port from a specified VLAN (tag)
-    def _port_remove_general_from_vlan(self, port, tag):
-        logging.debug("Removing general port %s from VLAN %d" % (port, tag))
-        self._configure()
-        self._cli("interface %s" % port)
-        self._cli("no switchport general pvid")
-        self._cli("switchport general allowed vlan remove %d" % tag)
-        self._end_configure()        
-
     # Wrapper around connection.send - by default, expect() the same
     # text we've sent, to remove it from the output from the
     # switch. For the few cases where we don't need that, override
@@ -490,15 +439,15 @@
     #buf = p.port_get_mode("fa12")
     #print "Port fa12 is in %s mode" % buf
 
-    # Test general stuff
-    print "Set fa6 to general mode"
-    p.port_set_mode("fa6", "general")
+    # Test access stuff
+    print "Set fa6 to access mode"
+    p.port_set_mode("fa6", "access")
     print "Move fa6 to VLAN 2"
-    p.port_set_general_vlan("fa6", 2)
-    buf = p.port_get_general_vlan("fa6")
+    p.port_set_access_vlan("fa6", 2)
+    buf = p.port_get_access_vlan("fa6")
     print "Read from switch: fa6 is on VLAN %s" % buf
     print "Move fa6 back to default VLAN 1"
-    p.port_set_general_vlan("fa6", 1)
+    p.port_set_access_vlan("fa6", 1)
     #print "And move fa6 back to a trunk port"
     #p.port_set_mode("fa6", "trunk")
     #buf = p.port_get_mode("fa6")