SDN Controller Programming Guide

157
String switchesJson = "{\"switches\":[]}";
// Recording phase (Define expectations)
EasyMock.expect(switchServiceMock.find(
EasyMock.isNull(SwitchFilter.class),
EasyMock.isNull(SortSpecification.class))).
andReturn(switches);
EasyMock.expect(jsonServiceMock.toJsonList(
EasyMock.same(switches), EasyMock.eq(Switch.class),
EasyMock.eq(true))).andReturn(switchesJson);
// Execution phase
EasyMock.replay(switchServiceMock, jsonServiceMock);
String response = get(BASE_PATH);
// Verification phase
assertResponseContains(response, switchesJson);
EasyMock.verify(switchServiceMock, jsonServiceMock);
}
...
}
Controller-Controller Communication via REST (Sideways APIs)
RESTful Web Services (or REST APIs) [2] [1] also represent a convenient way to enable
communication between controllers, and the HP VAN SDN Controller framework provides some
facilities to do so. This section illustrates a way to enable such communication. This section is
optional and the code illustrated here won’t be part of our sample application, it is just a section
dedicated to illustrate this useful communication mechanism. Also note this should not be the
preferred mechanism to enable communication between controllers, the HP VAN SDN Controller
Framework offers other services based on ZooKeeper [10] to achieve that. For more information
see HA Service on page 67.
Figure 53 illustrates the intuitive idea. In order to enable communication a new service in charge
of the communication is created to decouple the business logic from the specifics of the underlying
communication technology. The implementation of the communication service sends HTTP requests
to the destination REST Web Service and processed HTTP responses. By introducing such new
communication service it is possible to define higher-level (type-safe) communication methods.