SDN Controller Programming Guide
22
@Modified
protected void modified(Map<String, Object> config) {
someIntVariable = ConfigUtils.readInt(config, CONFIG_KEY, null, 100);
}
...
}
As the configuration property value can one of several different kinds of Java object (Integer, Long,
String, etc) a utility class is provided to read the appropriate Java object type from the
configuration map. The ConfigUtils.java class provides methods to read integers, longs, strings,
Booleans and ports from the configuration map of key -> value pairs. The caller must provide the
following information:
The configuration map
The key (string) for the desired property in the configuration map
A data Validator object (can be null)
A default value. The default value is returned if the provided key is not found in the
configuration map, if the key does not map to an Object of the desired type, or if a provided
data validator object rejects the value.
A Validator is a typed class which performs custom validation on a given configuration value. For
example, a data validator which only allows integer values between 10 and 20 is illustrated in the
following listing.
Configurable Property Validator Example:
...
import com.hp.sdn.misc.Validator;
public class MyValidator implements Validator<Integer> {
@Override
public boolean isValid(Integer value) {
return ((10 <= value) && (value <= 20));
}
}
To use this validator with the ConfigUtils class to obtain the configuration value from the
configuration map, just include it in the method call:
MyValidator myValidator = new MyValidator();
ConfigUtils.readInt(config, CONFIG_KEY, myValidator, 15);
OpenFlow
OpenFlow messages are sent and received between the controller and the switches (datapaths) it
manages. These messages are byte streams, the structure of which is documented in the OpenFlow
Protocol Specification documents published by the Open Networking Foundation (ONF) [29].
The Message Library is a Java implementation of the OpenFlow specification, providing facilities
for encoding and decoding OpenFlow messages from and to Java rich data types.
The Core Controller handles the connections from OpenFlow switches and provides the means for
upper layers of software to interact with those switches via the ControllerService API.