SDN Controller Programming Guide
119
Application Code
The following information walks through the code and shows how to implement the application.
This is useful as it illustrates different services in action.
Space doesn’t permit implementing the entire application, however this shows the major parts,
and finishing the implementation is a matter of creating a variation of what is shown. Javadocs
will be omitted to save space, however they are important and must be provided in production
code. Some code samples will contain comments (in green color) to assist illustrations; these
comments are not meant to remain in a real application though. Some lines of code are
highlighted (in yellow color) to denote an importat difference with previous illustrations of the same
code. You can get the complete sample application source code from the HP VAN SDN Controller
SDK [19].
NOTE
When the Application Generator (Automatic Workspace Creation) is used to create an application, the
application modules already contain source files that follow practices described in the following
information. Thus, the generated application can be used as starting point.
It’s important to note that some parts of the illustrated code are just suggestions (like the way
model objects are implemented); you are free to apply any technique and style you prefer,
however, the code illustrated follows the same philosophy as the controller’s so it helps to
understand the way the controller’s services are structured.
Defining Model Objects
The application requires some standard data structures that act as transfer objects [32]. This
example uses a Switch data structure to hold all the information about the Open Flow Switch,
shown in the following listing (note that a better name would be OpenFlowSwitch, but a shorter
name was selected due space limitations illustrating code samples).
Switch.java:
package com.hp.hm.model;
import com.hp.api.Id;
import com.hp.sdn.AbstractModel;
import com.hp.util.ip.IpAddress;
import com.hp.util.ip.MacAddress;
public class Switch extends AbstractModel<Switch, Long> {
...
private final MacAddress macAddress;
private IpAddress ipAddress;
private String friendlyName;
private ActiveState activeState;