Skip to content
Snippets Groups Projects
Commit 912ea9ae authored by Shudong Zhou's avatar Shudong Zhou
Browse files

Use port name instead of port number in port-channel config

parent 1598a6fd
No related branches found
No related tags found
No related merge requests found
...@@ -577,8 +577,8 @@ public class DeviceManagerImpl implements IDeviceManager, IOFMessageListener, ...@@ -577,8 +577,8 @@ public class DeviceManagerImpl implements IDeviceManager, IOFMessageListener,
* @param port_channel * @param port_channel
*/ */
protected void addPortToPortChannel(String switch_id, protected void addPortToPortChannel(String switch_id,
Integer port_no, String port_channel) { String port_name, String port_channel) {
String swPort = switch_id + port_no; String swPort = switch_id + port_name;
portChannelMap.put(swPort, port_channel); portChannelMap.put(swPort, port_channel);
} }
...@@ -590,11 +590,16 @@ public class DeviceManagerImpl implements IDeviceManager, IOFMessageListener, ...@@ -590,11 +590,16 @@ public class DeviceManagerImpl implements IDeviceManager, IOFMessageListener,
*/ */
protected boolean inSamePortChannel(SwitchPortTuple swPort1, protected boolean inSamePortChannel(SwitchPortTuple swPort1,
SwitchPortTuple swPort2) { 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); String portChannel1 = portChannelMap.get(key);
if (portChannel1 == null) if (portChannel1 == null)
return false; 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); String portChannel2 = portChannelMap.get(key);
if (portChannel2 == null) if (portChannel2 == null)
return false; return false;
...@@ -632,7 +637,7 @@ public class DeviceManagerImpl implements IDeviceManager, IOFMessageListener, ...@@ -632,7 +637,7 @@ public class DeviceManagerImpl implements IDeviceManager, IOFMessageListener,
"controller_hostattachmentpoint"; "controller_hostattachmentpoint";
private static final String DEVICE_NETWORK_ADDRESS_TABLE_NAME = private static final String DEVICE_NETWORK_ADDRESS_TABLE_NAME =
"controller_hostnetworkaddress"; "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 // Column names for the host table
private static final String MAC_COLUMN_NAME = "mac"; private static final String MAC_COLUMN_NAME = "mac";
...@@ -649,7 +654,7 @@ public class DeviceManagerImpl implements IDeviceManager, IOFMessageListener, ...@@ -649,7 +654,7 @@ public class DeviceManagerImpl implements IDeviceManager, IOFMessageListener,
private static final String NETWORK_ADDRESS_COLUMN_NAME = "ip"; private static final String NETWORK_ADDRESS_COLUMN_NAME = "ip";
// Column names for the port channel table // Column names for the port channel table
protected static final String PC_ID_COLUMN_NAME = "id"; 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_SWITCH_COLUMN_NAME = "switch";
protected static final String PC_PORT_COLUMN_NAME = "port"; protected static final String PC_PORT_COLUMN_NAME = "port";
...@@ -1597,8 +1602,8 @@ public class DeviceManagerImpl implements IDeviceManager, IOFMessageListener, ...@@ -1597,8 +1602,8 @@ public class DeviceManagerImpl implements IDeviceManager, IOFMessageListener,
while (pcResultSet.next()) { while (pcResultSet.next()) {
String port_channel = pcResultSet.getString(PORT_CHANNEL_COLUMN_NAME); String port_channel = pcResultSet.getString(PORT_CHANNEL_COLUMN_NAME);
String switch_id = pcResultSet.getString(PC_SWITCH_COLUMN_NAME); String switch_id = pcResultSet.getString(PC_SWITCH_COLUMN_NAME);
Integer port_no = pcResultSet.getInt(PC_PORT_COLUMN_NAME); String port_name = pcResultSet.getString(PC_PORT_COLUMN_NAME);
devMgrMaps.addPortToPortChannel(switch_id, port_no, port_channel); devMgrMaps.addPortToPortChannel(switch_id, port_name, port_channel);
} }
return true; return true;
} catch (StorageException e) { } catch (StorageException e) {
......
...@@ -47,6 +47,7 @@ import org.junit.Test; ...@@ -47,6 +47,7 @@ import org.junit.Test;
import org.openflow.protocol.OFPacketIn; import org.openflow.protocol.OFPacketIn;
import org.openflow.protocol.OFType; import org.openflow.protocol.OFType;
import org.openflow.protocol.OFPacketIn.OFPacketInReason; import org.openflow.protocol.OFPacketIn.OFPacketInReason;
import org.openflow.protocol.OFPhysicalPort;
/** /**
* *
...@@ -356,6 +357,10 @@ public class DeviceManagerImplTest extends FloodlightTestCase { ...@@ -356,6 +357,10 @@ public class DeviceManagerImplTest extends FloodlightTestCase {
@Test @Test
public void testAttachmentPointFlapping() throws Exception { 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(); byte[] dataLayerSource = ((Ethernet)this.testPacket).getSourceMACAddress();
...@@ -364,6 +369,8 @@ public class DeviceManagerImplTest extends FloodlightTestCase { ...@@ -364,6 +369,8 @@ public class DeviceManagerImplTest extends FloodlightTestCase {
expect(mockSwitch.getId()).andReturn(1L).anyTimes(); expect(mockSwitch.getId()).andReturn(1L).anyTimes();
expect(mockSwitch.getStringId()).andReturn("00:00:00:00:00:00:00:01").anyTimes(); expect(mockSwitch.getStringId()).andReturn("00:00:00:00:00:00:00:01").anyTimes();
ITopology mockTopology = createMock(ITopology.class); 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))) expect(mockTopology.isInternal(new SwitchPortTuple(mockSwitch, 1)))
.andReturn(false).atLeastOnce(); .andReturn(false).atLeastOnce();
expect(mockTopology.isInternal(new SwitchPortTuple(mockSwitch, 2))) expect(mockTopology.isInternal(new SwitchPortTuple(mockSwitch, 2)))
...@@ -401,18 +408,18 @@ public class DeviceManagerImplTest extends FloodlightTestCase { ...@@ -401,18 +408,18 @@ public class DeviceManagerImplTest extends FloodlightTestCase {
static { static {
pcPort1 = new HashMap<String, Object>(); pcPort1 = new HashMap<String, Object>();
pcPort1.put(DeviceManagerImpl.PORT_CHANNEL_COLUMN_NAME, "channel"); 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_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; private static final Map<String, Object> pcPort2;
static { static {
pcPort2 = new HashMap<String, Object>(); pcPort2 = new HashMap<String, Object>();
pcPort2.put(DeviceManagerImpl.PORT_CHANNEL_COLUMN_NAME, "channel"); 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_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() { private void setupPortChannel() {
...@@ -436,12 +443,18 @@ public class DeviceManagerImplTest extends FloodlightTestCase { ...@@ -436,12 +443,18 @@ public class DeviceManagerImplTest extends FloodlightTestCase {
*/ */
@Test @Test
public void testPortChannel() throws Exception { public void testPortChannel() throws Exception {
OFPhysicalPort port1 = new OFPhysicalPort();
OFPhysicalPort port2 = new OFPhysicalPort();
port1.setName("port1");
port2.setName("port2");
setupPortChannel(); setupPortChannel();
byte[] dataLayerSource = ((Ethernet)this.testPacket).getSourceMACAddress(); byte[] dataLayerSource = ((Ethernet)this.testPacket).getSourceMACAddress();
// Mock up our expected behavior // Mock up our expected behavior
IOFSwitch mockSwitch = createMock(IOFSwitch.class); 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.getId()).andReturn(1L).anyTimes();
expect(mockSwitch.getStringId()).andReturn("00:00:00:00:00:00:00:01").anyTimes(); expect(mockSwitch.getStringId()).andReturn("00:00:00:00:00:00:00:01").anyTimes();
ITopology mockTopology = createMock(ITopology.class); ITopology mockTopology = createMock(ITopology.class);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment