diff --git a/src/main/java/net/floodlightcontroller/core/internal/Controller.java b/src/main/java/net/floodlightcontroller/core/internal/Controller.java index ef49cded3fc36028bfde24612ed0c2b8cabeddf0..eb8322c4e03fb9ed5d3b04a971684dbd48840788 100644 --- a/src/main/java/net/floodlightcontroller/core/internal/Controller.java +++ b/src/main/java/net/floodlightcontroller/core/internal/Controller.java @@ -720,6 +720,23 @@ public class Controller implements IFloodlightProviderService, IStorageSourceLis } log.info("Number of worker threads set to {}", this.workerThreads); + + /** + * Tulio Ribeiro + */ + String controllerId = configParams.get("controllerId"); + if (!Strings.isNullOrEmpty(controllerId)) { + try { + this.controllerId = controllerId; + } catch (Exception e) { + log.error("Invalid controlelrId {}, {}", controllerId, e); + throw new FloodlightModuleException("Invalid controllerId of " + controllerId + " in config"); + } + } + log.info("ControllerId set to {}", this.controllerId); + + + String addresses = configParams.get("openFlowAddresses"); if (!Strings.isNullOrEmpty(addresses)) { try { diff --git a/src/main/java/net/floodlightcontroller/core/internal/OFChannelHandler.java b/src/main/java/net/floodlightcontroller/core/internal/OFChannelHandler.java index 0611648a5252cd623f1ade599777b3a9151c0067..f3d274f68637f087ae53f1e1df53e14d9da44953 100644 --- a/src/main/java/net/floodlightcontroller/core/internal/OFChannelHandler.java +++ b/src/main/java/net/floodlightcontroller/core/internal/OFChannelHandler.java @@ -39,6 +39,7 @@ import org.projectfloodlight.openflow.protocol.OFHelloElem; import org.projectfloodlight.openflow.protocol.OFHelloElemVersionbitmap; import org.projectfloodlight.openflow.protocol.OFMessage; import org.projectfloodlight.openflow.protocol.OFPortStatus; +import org.projectfloodlight.openflow.protocol.OFRoleStatus; import org.projectfloodlight.openflow.protocol.OFType; import org.projectfloodlight.openflow.protocol.OFVersion; import org.projectfloodlight.openflow.protocol.ver13.OFHelloElemTypeSerializerVer13; @@ -687,7 +688,7 @@ class OFChannelHandler extends SimpleChannelInboundHandler<Iterable<OFMessage>> @Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { - log.debug("channelIdle on OFChannelHandler {}", String.format("%08x", System.identityHashCode(this))); + //log.debug("channelIdle on OFChannelHandler {}", String.format("%08x", System.identityHashCode(this))); OFChannelHandler handler = ctx.pipeline().get(OFChannelHandler.class); handler.sendEchoRequest(); } @@ -831,7 +832,7 @@ class OFChannelHandler extends SimpleChannelInboundHandler<Iterable<OFMessage>> .build(); write(reply); } - + private void write(OFMessage m) { channel.writeAndFlush(Collections.singletonList(m)); } diff --git a/src/main/java/net/floodlightcontroller/core/internal/OFSwitchHandshakeHandler.java b/src/main/java/net/floodlightcontroller/core/internal/OFSwitchHandshakeHandler.java index 47671f5cedd4b502bfc8aa69a7354943568d62c2..e8121342384da9f697d3dd257b746478bb346caf 100644 --- a/src/main/java/net/floodlightcontroller/core/internal/OFSwitchHandshakeHandler.java +++ b/src/main/java/net/floodlightcontroller/core/internal/OFSwitchHandshakeHandler.java @@ -55,6 +55,7 @@ import org.projectfloodlight.openflow.protocol.OFPortStatus; import org.projectfloodlight.openflow.protocol.OFQueueGetConfigReply; import org.projectfloodlight.openflow.protocol.OFRoleReply; import org.projectfloodlight.openflow.protocol.OFRoleRequest; +import org.projectfloodlight.openflow.protocol.OFRoleStatus; import org.projectfloodlight.openflow.protocol.OFSetConfig; import org.projectfloodlight.openflow.protocol.OFStatsReply; import org.projectfloodlight.openflow.protocol.OFStatsReplyFlags; @@ -617,6 +618,13 @@ public class OFSwitchHandshakeHandler implements IOFConnectionListener { void processOFRoleRequest(OFRoleRequest m) { unhandledMessageWritten(m); } + + /** + * Tulio Ribeiro + */ + void processOFRoleStatus(OFRoleStatus m){ + unhandledMessageReceived(m); + } void processOFNiciraControllerRoleRequest(OFNiciraControllerRoleRequest m) { unhandledMessageWritten(m); @@ -863,6 +871,9 @@ public class OFSwitchHandshakeHandler implements IOFConnectionListener { case EXPERIMENTER: processOFExperimenter((OFExperimenter) m); break; + case ROLE_STATUS: + processOFRoleStatus((OFRoleStatus) m); + break; default: illegalMessageReceived(m); break; @@ -1313,7 +1324,19 @@ public class OFSwitchHandshakeHandler implements IOFConnectionListener { @Override void enterState(){ - sendRoleRequest(roleManager.getOFControllerRole()); + //sendRoleRequest(roleManager.getOFControllerRole());//original + /** + * Tulio Ribeiro + * Retrieve role from floodlightdefault.properties configuration file + * swId;Role 00:00:00:00:00:00:00:01;ROLE_SLAVE + * If not defined there, the role will be set as MASTER + */ + OFControllerRole role = OFControllerRole.ROLE_MASTER; + if(OFSwitchManager.switchInitialRole.containsKey(mainConnection.getDatapathId())){ + role = OFSwitchManager.switchInitialRole.get(mainConnection.getDatapathId()); + log.info("Defining switch role from config file: {}", role); + } + sendRoleRequest(role); } } @@ -1413,6 +1436,35 @@ public class OFSwitchHandshakeHandler implements IOFConnectionListener { void processOFRoleRequest(OFRoleRequest m) { sendRoleRequest(m); } + + @Override + void processOFRoleStatus(OFRoleStatus m) { + /** + * Tulio Ribeiro + * + * Controller roles. + * enum ofp_controller_role { + * OFPCR_ROLE_NOCHANGE = 0, Don’t change current role. + * OFPCR_ROLE_EQUAL = 1, Default role, full access. + * OFPCR_ROLE_MASTER = 2, Full access, at most one master. + * OFPCR_ROLE_SLAVE = 3, Read-only access. + * }; + */ + //log.info("Processing roleStatus from MasterState..."); + long role = m.getRole(); + if(role==3){ + sendRoleRequest(OFControllerRole.ROLE_SLAVE); + OFSwitchManager.switchInitialRole.remove(mainConnection.getDatapathId()); + OFSwitchManager.switchInitialRole.put(mainConnection.getDatapathId(), + OFControllerRole.ROLE_SLAVE); + } + else if (role==2) + sendRoleRequest(OFControllerRole.ROLE_MASTER); + else if (role==1) + sendRoleRequest(OFControllerRole.ROLE_EQUAL); + else + sendRoleRequest(OFControllerRole.ROLE_NOCHANGE); + } @Override void processOFNiciraControllerRoleRequest(OFNiciraControllerRoleRequest m) { @@ -1530,6 +1582,30 @@ public class OFSwitchHandshakeHandler implements IOFConnectionListener { void processOFRoleRequest(OFRoleRequest m) { sendRoleRequest(m); } + + @Override + void processOFRoleStatus(OFRoleStatus m) { + /** + * Tulio Ribeiro + * + * Controller roles. + * enum ofp_controller_role { + * OFPCR_ROLE_NOCHANGE = 0, Don’t change current role. + * OFPCR_ROLE_EQUAL = 1, Default role, full access. + * OFPCR_ROLE_MASTER = 2, Full access, at most one master. + * OFPCR_ROLE_SLAVE = 3, Read-only access. + * }; + */ + long role = m.getRole(); + if(role==3) + sendRoleRequest(OFControllerRole.ROLE_SLAVE); + else if (role==2) + sendRoleRequest(OFControllerRole.ROLE_MASTER); + else if (role==1) + sendRoleRequest(OFControllerRole.ROLE_EQUAL); + else + sendRoleRequest(OFControllerRole.ROLE_NOCHANGE); + } @Override void processOFNiciraControllerRoleRequest(OFNiciraControllerRoleRequest m) { diff --git a/src/main/java/net/floodlightcontroller/core/internal/OFSwitchManager.java b/src/main/java/net/floodlightcontroller/core/internal/OFSwitchManager.java index 9b22851539d7f2e344514bcc9583a7ea23544145..530be7059f3f6a107d30995e09a1d0511ace4aa4 100644 --- a/src/main/java/net/floodlightcontroller/core/internal/OFSwitchManager.java +++ b/src/main/java/net/floodlightcontroller/core/internal/OFSwitchManager.java @@ -117,6 +117,11 @@ public class OFSwitchManager implements IOFSwitchManager, INewOFConnectionListen private ConcurrentHashMap<DatapathId, OFSwitchHandshakeHandler> switchHandlers; private ConcurrentHashMap<DatapathId, IOFSwitchBackend> switches; private ConcurrentHashMap<DatapathId, IOFSwitch> syncedSwitches; + + /** + * Tulio Ribeiro + */ + protected static Map<DatapathId, OFControllerRole> switchInitialRole; private ISwitchDriverRegistry driverRegistry; @@ -728,6 +733,16 @@ public class OFSwitchManager implements IOFSwitchManager, INewOFConnectionListen log.info("Clear switch flow tables on each transition to master: TRUE"); OFSwitchManager.clearTablesOnEachTransitionToMaster = true; } + + + /** + * Tulio Ribeiro + */ + //Define initial role per switch + String switchesInitialState = configParams.get("switchesInitialState"); + switchInitialRole = jsonToSwitchInitialRoleMap(switchesInitialState); + + log.debug("SwitchInitialRole: {}", switchInitialRole.entrySet()); /* * Get default max table for forward to controller flows. @@ -1169,4 +1184,63 @@ public class OFSwitchManager implements IOFSwitchManager, INewOFConnectionListen addUpdateToQueue(update); }*/ } + + + /** + * Tulio Ribeiro + * @param String json + * @return Map<DatapathId, OFControllerRole> + */ + private static Map<DatapathId, OFControllerRole> jsonToSwitchInitialRoleMap(String json) { + MappingJsonFactory f = new MappingJsonFactory(); + JsonParser jp; + Map<DatapathId, OFControllerRole> retValue = new HashMap<DatapathId, OFControllerRole>(); + + if (json == null || json.isEmpty()) { + return retValue; + } + + try { + try { + jp = f.createParser(json); + } catch (JsonParseException e) { + throw new IOException(e); + } + + jp.nextToken(); + if (jp.getCurrentToken() != JsonToken.START_OBJECT) { + throw new IOException("Expected START_OBJECT"); + } + + while (jp.nextToken() != JsonToken.END_OBJECT) { + if (jp.getCurrentToken() != JsonToken.FIELD_NAME) { + throw new IOException("Expected FIELD_NAME"); + } + + String n = jp.getCurrentName(); + jp.nextToken(); + if (jp.getText().equals("")) { + continue; + } + + DatapathId dpid; + OFControllerRole ofcr=OFControllerRole.ROLE_NOCHANGE; + + try { + n = n.trim(); + dpid = DatapathId.of(n); + ofcr = OFControllerRole.valueOf(jp.getText()); + retValue.put(dpid, ofcr); + + } catch (NumberFormatException e) { + log.error("Invalid DPID format: {}, or OFControllerRole: {}", n, ofcr); + } + } + } catch (IOException e) { + log.error("Problem: {}", e); + } + return retValue; + } + + } diff --git a/src/main/resources/floodlightdefault.properties b/src/main/resources/floodlightdefault.properties index 89bf32381355331dd93a011d0e59d2a2581d4d5d..fe6588bab493bc16baa86d5f4542ca3e1de72353 100644 --- a/src/main/resources/floodlightdefault.properties +++ b/src/main/resources/floodlightdefault.properties @@ -25,6 +25,8 @@ net.floodlightcontroller.forwarding.Forwarding.match=vlan, mac, ip, transport net.floodlightcontroller.forwarding.Forwarding.flood-arp=NO net.floodlightcontroller.core.internal.FloodlightProvider.openFlowPort=6653 net.floodlightcontroller.core.internal.FloodlightProvider.role=ACTIVE +net.floodlightcontroller.core.internal.FloodlightProvider.workerThreads=8 +net.floodlightcontroller.core.internal.FloodlightProvider.controllerId=C1 net.floodlightcontroller.linkdiscovery.internal.LinkDiscoveryManager.latency-history-size=10 net.floodlightcontroller.linkdiscovery.internal.LinkDiscoveryManager.latency-update-threshold=0.5 net.floodlightcontroller.core.internal.OFSwitchManager.defaultMaxTablesToReceiveTableMissFlow=1 @@ -35,6 +37,7 @@ net.floodlightcontroller.core.internal.OFSwitchManager.keyStorePath=/path/to/you net.floodlightcontroller.core.internal.OFSwitchManager.keyStorePassword=your-keystore-password net.floodlightcontroller.core.internal.OFSwitchManager.useSsl=NO net.floodlightcontroller.core.internal.OFSwitchManager.supportedOpenFlowVersions=1.0, 1.1, 1.2, 1.3, 1.4 +net.floodlightcontroller.core.internal.OFSwitchManager.switchesInitialState={"00:00:00:00:00:00:00:01":"ROLE_MASTER","00:00:00:00:00:00:00:02":"ROLE_MASTER", "00:00:00:00:00:00:00:03":"ROLE_MASTER", "00:00:00:00:00:00:00:04":"ROLE_MASTER","00:00:00:00:00:00:00:05":"ROLE_MASTER"} net.floodlightcontroller.restserver.RestApiServer.keyStorePath=/path/to/your/keystore-file.jks net.floodlightcontroller.restserver.RestApiServer.keyStorePassword=your-keystore-password net.floodlightcontroller.restserver.RestApiServer.httpsNeedClientAuthentication=NO diff --git a/src/main/resources/floodlightdefault.properties2 b/src/main/resources/floodlightdefault.properties2 new file mode 100644 index 0000000000000000000000000000000000000000..38c2b7b19d0007c6cea2febff796b431cecef4b8 --- /dev/null +++ b/src/main/resources/floodlightdefault.properties2 @@ -0,0 +1,40 @@ +floodlight.modules=\ +net.floodlightcontroller.storage.memory.MemoryStorageSource,\ +net.floodlightcontroller.core.internal.FloodlightProvider,\ +net.floodlightcontroller.threadpool.ThreadPool,\ +net.floodlightcontroller.debugcounter.DebugCounterServiceImpl,\ +net.floodlightcontroller.perfmon.PktInProcessingTime,\ +net.floodlightcontroller.debugevent.DebugEventService,\ +net.floodlightcontroller.staticflowentry.StaticFlowEntryPusher,\ +net.floodlightcontroller.topology.TopologyManager,\ +net.floodlightcontroller.forwarding.Forwarding,\ +net.floodlightcontroller.linkdiscovery.internal.LinkDiscoveryManager,\ +net.floodlightcontroller.ui.web.StaticWebRoutable,\ +net.floodlightcontroller.loadbalancer.LoadBalancer,\ +net.floodlightcontroller.firewall.Firewall,\ +net.floodlightcontroller.devicemanager.internal.DeviceManagerImpl,\ +net.floodlightcontroller.accesscontrollist.ACL,\ +net.floodlightcontroller.statistics.StatisticsCollector +org.sdnplatform.sync.internal.SyncManager.authScheme=CHALLENGE_RESPONSE +org.sdnplatform.sync.internal.SyncManager.keyStorePath=/etc/floodlight/auth_credentials.jceks +org.sdnplatform.sync.internal.SyncManager.dbPath=/var/lib/floodlight2/ +org.sdnplatform.sync.internal.SyncManager.port=7742 +net.floodlightcontroller.forwarding.Forwarding.match=vlan, mac, ip, transport +net.floodlightcontroller.forwarding.Forwarding.flood-arp=NO +net.floodlightcontroller.core.internal.FloodlightProvider.openFlowPort=7753 +net.floodlightcontroller.core.internal.FloodlightProvider.role=ACTIVE +net.floodlightcontroller.core.internal.FloodlightProvider.workerThreads=8 +net.floodlightcontroller.core.internal.FloodlightProvider.controllerId=C2 +net.floodlightcontroller.linkdiscovery.internal.LinkDiscoveryManager.latency-history-size=10 +net.floodlightcontroller.linkdiscovery.internal.LinkDiscoveryManager.latency-update-threshold=0.5 +net.floodlightcontroller.core.internal.OFSwitchManager.defaultMaxTablesToReceiveTableMissFlow=1 +net.floodlightcontroller.core.internal.OFSwitchManager.maxTablesToReceiveTableMissFlowPerDpid={"00:00:00:00:00:00:00:01":"1","2":"1"} +net.floodlightcontroller.core.internal.OFSwitchManager.clearTablesOnInitialHandshakeAsMaster=YES +net.floodlightcontroller.core.internal.OFSwitchManager.clearTablesOnEachTransitionToMaster=YES +net.floodlightcontroller.core.internal.OFSwitchManager.keyStorePath=/path/to/your/keystore-file.jks +net.floodlightcontroller.core.internal.OFSwitchManager.keyStorePassword=your-keystore-password +net.floodlightcontroller.core.internal.OFSwitchManager.useSsl=NO +net.floodlightcontroller.core.internal.OFSwitchManager.supportedOpenFlowVersions=1.0, 1.1, 1.2, 1.3, 1.4 +net.floodlightcontroller.core.internal.OFSwitchManager.switchesInitialState={"00:00:00:00:00:00:00:01":"ROLE_SLAVE","00:00:00:00:00:00:00:02":"ROLE_SLAVE", "00:00:00:00:00:00:00:03":"ROLE_SLAVE", "00:00:00:00:00:00:00:04":"ROLE_MASTER","00:00:00:00:00:00:00:05":"ROLE_MASTER"} +net.floodlightcontroller.statistics.StatisticsCollector.enable=FALSE +net.floodlightcontroller.statistics.StatisticsCollector.collectionIntervalPortStatsSeconds=10 \ No newline at end of file diff --git a/src/main/resources/logback-test.xml b/src/main/resources/logback-test.xml index 8fa1e8f86065f20fa51ea0b42336af21b4e15cdc..5578513acfb1897369b607d4d930f3283a409a77 100644 --- a/src/main/resources/logback-test.xml +++ b/src/main/resources/logback-test.xml @@ -17,8 +17,11 @@ <logger name="org.sdnplatform" level="INFO"></logger> <logger name="net.floodlightcontroller.devicemanager" level="INFO"></logger> <logger name="net.floodlightcontroller.linkdiscovery" level="INFO"></logger> - <logger name="net.floodlightcontroller.forwarding" level="INFO"></logger> + <logger name="net.floodlightcontroller.forwarding" level="TRACE"></logger> <logger name="net.floodlightcontroller.core" level="INFO"></logger> <logger name="net.floodlightcontroller.topology" level="INFO" ></logger> <logger name="org.projectfloodlight.openflow" level="INFO" ></logger> + <logger name="net.floodlightcontroller.core.internal.OFSwitchManager" level="TRACE"></logger> + <logger name="net.floodlightcontroller.core.internal.OFSwitchHandshakeHandler" level="TRACE"></logger> + <logger name="net.floodlightcontroller.core.internal.OFChannelHandler" level="TRACE"></logger> </configuration>