1. In main, first load the module, start the rest service, and then build an instance that implements the Ifloodlightproviderservice interface (that is, the controller) and execute it; 2. Next enter the controller's run () method, at which time all the environment initialization work is complete. Build a TCP server based on Netty, the most important is the setup of Pipelining factory openflowpipelinefactory, Inside is controller high, dirty processing handler (Detailed details see = = =).
When the channel is established, the messagereceived () method is called after receiving a message from the SW and distributed to the processofmessage for detailed processing according to the different types of msg; Assuming that the message requires a response to the SW, or that other listeners are interested, call handlemessage for additional processing, and the code is posted. protected void Handlemessage (Iofswitch SW, Ofmessage m, Floodlightcontext Bcontext) {
Ethernet eth = null;
Switch (M.gettype ()) {
Case packet_in:
Ofpacketin pi = (ofpacketin) m;
Always true by default
if (Controller.always_decode_eth) {
ETH = new Ethernet (); Parse the PACKET_IN message into the ETH, so the following bcstore can be stored directly
eth.deserialize (pi.getpacketdata (), 0, Pi.getpacketdata (). length);
Counterstore.updatepacketincounters (SW, M, ETH);
}
//Fall through to the default case ...
Default
List<iofmessagelistener> listeners = null;
if (Messagelisteners.containskey (M.gettype ())) {
Listeners = Messagelisteners.get (M.gettype ()). Getorderedlisteners ();
}
floodlightcontext BC = NULL;
if (listeners! = null) {
Check If floodlight context is passed from the calling
function, if so use that floodlight context, otherwise
Allocate one
if (Bcontext = = null) {
BC = Flcontext_alloc ();
} else {
BC = Bcontext;
}
if (ETH! = null) {
IFloodlightProviderService.bcStore.put (Bc,ifloodlightproviderservice.context_pi_payload, ETH); //cache to HashMap. So when we join our own module to listen to Packetin messages. can be removed from it. Do your own business processing.
}
Command cmd;
for (Iofmessagelistener listener:listeners) {
if (listener instanceof Iofswitchfilter) {
if (! ( (iofswitchfilter) listener). isinterested (SW)) {
Continue
}
}
Traverse all listener that are of interest to packetin. To run their receive method separately;
cmd = listener.receive (SW, M, BC);
if (Command.STOP.equals (cmd)) {
Break
} } }
if ((Bcontext = = null) && (BC = null)) flcontext_free (BC);
} }
3. Process the update message of SW at any time in the loop.
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
Floodlight Start-Up process analysis