From 912ea9ae2fdbac51cbe8a8b598737e4fc89e7c80 Mon Sep 17 00:00:00 2001 From: Shudong Zhou <shudongzhou@gmail.com> Date: Mon, 13 Feb 2012 17:09:39 -0800 Subject: [PATCH] Use port name instead of port number in port-channel config --- .../internal/DeviceManagerImpl.java | 21 ++++++++++------- .../internal/DeviceManagerImplTest.java | 23 +++++++++++++++---- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImpl.java b/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImpl.java index f75556df2..bd1c60b83 100755 --- a/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImpl.java +++ b/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImpl.java @@ -577,8 +577,8 @@ public class DeviceManagerImpl implements IDeviceManager, IOFMessageListener, * @param port_channel */ protected void addPortToPortChannel(String switch_id, - Integer port_no, String port_channel) { - String swPort = switch_id + port_no; + String port_name, String port_channel) { + String swPort = switch_id + port_name; portChannelMap.put(swPort, port_channel); } @@ -590,11 +590,16 @@ public class DeviceManagerImpl implements IDeviceManager, IOFMessageListener, */ protected boolean inSamePortChannel(SwitchPortTuple swPort1, SwitchPortTuple swPort2) { - String key = swPort1.getSw().getStringId() + swPort1.getPort(); + IOFSwitch sw = swPort1.getSw(); + String portName = sw.getPort(swPort1.getPort()).getName(); + String key = sw.getStringId() + portName; String portChannel1 = portChannelMap.get(key); if (portChannel1 == null) return false; - key = swPort2.getSw().getStringId() + swPort2.getPort(); + + sw = swPort2.getSw(); + portName = sw.getPort(swPort2.getPort()).getName(); + key = sw.getStringId() + portName; String portChannel2 = portChannelMap.get(key); if (portChannel2 == null) return false; @@ -632,7 +637,7 @@ public class DeviceManagerImpl implements IDeviceManager, IOFMessageListener, "controller_hostattachmentpoint"; private static final String DEVICE_NETWORK_ADDRESS_TABLE_NAME = "controller_hostnetworkaddress"; - protected static final String PORT_CHANNEL_TABLE_NAME = "controller_portchannel"; + protected static final String PORT_CHANNEL_TABLE_NAME = "controller_portchannelconfig"; // Column names for the host table private static final String MAC_COLUMN_NAME = "mac"; @@ -649,7 +654,7 @@ public class DeviceManagerImpl implements IDeviceManager, IOFMessageListener, private static final String NETWORK_ADDRESS_COLUMN_NAME = "ip"; // Column names for the port channel table protected static final String PC_ID_COLUMN_NAME = "id"; - protected static final String PORT_CHANNEL_COLUMN_NAME = "port_channel"; + protected static final String PORT_CHANNEL_COLUMN_NAME = "port_channel_id"; protected static final String PC_SWITCH_COLUMN_NAME = "switch"; protected static final String PC_PORT_COLUMN_NAME = "port"; @@ -1597,8 +1602,8 @@ public class DeviceManagerImpl implements IDeviceManager, IOFMessageListener, while (pcResultSet.next()) { String port_channel = pcResultSet.getString(PORT_CHANNEL_COLUMN_NAME); String switch_id = pcResultSet.getString(PC_SWITCH_COLUMN_NAME); - Integer port_no = pcResultSet.getInt(PC_PORT_COLUMN_NAME); - devMgrMaps.addPortToPortChannel(switch_id, port_no, port_channel); + String port_name = pcResultSet.getString(PC_PORT_COLUMN_NAME); + devMgrMaps.addPortToPortChannel(switch_id, port_name, port_channel); } return true; } catch (StorageException e) { diff --git a/src/test/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImplTest.java b/src/test/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImplTest.java index 1af5907c4..51f14efe7 100644 --- a/src/test/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImplTest.java +++ b/src/test/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImplTest.java @@ -47,6 +47,7 @@ import org.junit.Test; import org.openflow.protocol.OFPacketIn; import org.openflow.protocol.OFType; import org.openflow.protocol.OFPacketIn.OFPacketInReason; +import org.openflow.protocol.OFPhysicalPort; /** * @@ -356,6 +357,10 @@ public class DeviceManagerImplTest extends FloodlightTestCase { @Test public void testAttachmentPointFlapping() throws Exception { + OFPhysicalPort port1 = new OFPhysicalPort(); + OFPhysicalPort port2 = new OFPhysicalPort(); + port1.setName("port1"); + port2.setName("port2"); byte[] dataLayerSource = ((Ethernet)this.testPacket).getSourceMACAddress(); @@ -364,6 +369,8 @@ public class DeviceManagerImplTest extends FloodlightTestCase { expect(mockSwitch.getId()).andReturn(1L).anyTimes(); expect(mockSwitch.getStringId()).andReturn("00:00:00:00:00:00:00:01").anyTimes(); ITopology mockTopology = createMock(ITopology.class); + expect(mockSwitch.getPort((short)1)).andReturn(port1).anyTimes(); + expect(mockSwitch.getPort((short)2)).andReturn(port2).anyTimes(); expect(mockTopology.isInternal(new SwitchPortTuple(mockSwitch, 1))) .andReturn(false).atLeastOnce(); expect(mockTopology.isInternal(new SwitchPortTuple(mockSwitch, 2))) @@ -401,18 +408,18 @@ public class DeviceManagerImplTest extends FloodlightTestCase { static { pcPort1 = new HashMap<String, Object>(); pcPort1.put(DeviceManagerImpl.PORT_CHANNEL_COLUMN_NAME, "channel"); - pcPort1.put(DeviceManagerImpl.PC_PORT_COLUMN_NAME, 1); + pcPort1.put(DeviceManagerImpl.PC_PORT_COLUMN_NAME, "port1"); pcPort1.put(DeviceManagerImpl.PC_SWITCH_COLUMN_NAME, "00:00:00:00:00:00:00:01"); - pcPort1.put(DeviceManagerImpl.PC_ID_COLUMN_NAME, "00:00:00:00:00:00:00:01|1"); + pcPort1.put(DeviceManagerImpl.PC_ID_COLUMN_NAME, "00:00:00:00:00:00:00:01|port1"); } private static final Map<String, Object> pcPort2; static { pcPort2 = new HashMap<String, Object>(); pcPort2.put(DeviceManagerImpl.PORT_CHANNEL_COLUMN_NAME, "channel"); - pcPort2.put(DeviceManagerImpl.PC_PORT_COLUMN_NAME, 2); + pcPort2.put(DeviceManagerImpl.PC_PORT_COLUMN_NAME, "port2"); pcPort2.put(DeviceManagerImpl.PC_SWITCH_COLUMN_NAME, "00:00:00:00:00:00:00:01"); - pcPort2.put(DeviceManagerImpl.PC_ID_COLUMN_NAME, "00:00:00:00:00:00:00:01|2"); + pcPort2.put(DeviceManagerImpl.PC_ID_COLUMN_NAME, "00:00:00:00:00:00:00:01|port2"); } private void setupPortChannel() { @@ -436,12 +443,18 @@ public class DeviceManagerImplTest extends FloodlightTestCase { */ @Test public void testPortChannel() throws Exception { - + OFPhysicalPort port1 = new OFPhysicalPort(); + OFPhysicalPort port2 = new OFPhysicalPort(); + port1.setName("port1"); + port2.setName("port2"); + setupPortChannel(); byte[] dataLayerSource = ((Ethernet)this.testPacket).getSourceMACAddress(); // Mock up our expected behavior IOFSwitch mockSwitch = createMock(IOFSwitch.class); + expect(mockSwitch.getPort((short)1)).andReturn(port1).anyTimes(); + expect(mockSwitch.getPort((short)2)).andReturn(port2).anyTimes(); expect(mockSwitch.getId()).andReturn(1L).anyTimes(); expect(mockSwitch.getStringId()).andReturn("00:00:00:00:00:00:00:01").anyTimes(); ITopology mockTopology = createMock(ITopology.class); -- GitLab