SDN Controller Programming Guide

122
Based on these conditions we will create a filter for the Open Flow switch class as illustrated in the
following listing.
SwitchFilter.java:
package com.hp.hm.model;
import com.hp.util.filter.EqualityCondition;
import com.hp.util.filter.SetCondition;
import com.hp.util.filter.StringCondition;
...
public class SwitchFilter {
private EqualityCondition<MacAddress> macAddressCondition;
private SetCondition<IpAddress> ipAddressCondition;
private StringCondition friendlyNameCondition;
private EqualityCondition<ActiveState> activeStateCondition;
...
// Implement setters and getters for all conditions.
// Good practice to override toString()
}
The following listing depicts a usage example: Create a filter to retrieve all open flow switches in
non-active state with a friendly name that contains the text ‘My Switchand an IP Address that is
not one of the following: [192.168.1.2, 192.168.1.3].
Switch Filter Usage Example:
SwitchFilter filter = new SwitchFilter();
filter.setActiveStateCondition(new
EqualityCondition<ActiveState>(ActiveState.OFF,
EqualityCondition.Mode.EQUAL));
filter.setFriendlyNameCondition(new StringCondition("My Switch",
StringCondition.Mode.CONTAINS));
Set<IpAddress> ips = new HashSet<IpAddress>();
ips.add(IpAddress.valueOf("192.168.1.2"));
ips.add(IpAddress.valueOf("192.168.1.3"));
filter.setIpAddressCondition(new SetCondition<IpAddress>(ips,
SetCondition.Mode.NOT_IN));
Following a similar approach, create a Java enumeration to represent the sort possibilities in which
open flow switches can be retrieved. This helps decoupling the service consumer from the way
sorting is implemented in lower level layers (like column names in a database). The following
listing shows the Open Flow Switch sort possibilities and the next listing depicts a usage example:
When retrieving switches the primary order shall be Mac Address ascending, then Active State
descending and lastly Friendly Name ascending.
SwitchSortKey.java:
package com.hp.hm.model;
public enum SwitchSortKey {