break;
}
- if (index - buf.readerIndex() >= maxFrameLength) {
- /*
- * Changing this limit to being a warning, we do not wish to "break" in scale environment
- * and currently this limits the ovs of having only around 50 ports defined...
- * I do acknowledge the fast that this might be risky in case of huge amount of strings
- * in which the controller can crash with an OOM, however seems that we need a really huge
- * ovs to reach that limit.
- */
-
- //We do not want to issue a log message on every extent of the buffer
- //hence logging only once
- if (!maxFrameLimitWasReached) {
- maxFrameLimitWasReached = true;
- LOG.warn("***** OVSDB Frame limit of {} bytes has been reached! *****", this.maxFrameLength);
- }
+ /*
+ * Changing this limit to being a warning, we do not wish to "break" in scale environment
+ * and currently this limits the ovs of having only around 50 ports defined...
+ * I do acknowledge the fast that this might be risky in case of huge amount of strings
+ * in which the controller can crash with an OOM, however seems that we need a really huge
+ * ovs to reach that limit.
+ */
+
+ //We do not want to issue a log message on every extent of the buffer
+ //hence logging only once
+ if (index - buf.readerIndex() >= maxFrameLength && !maxFrameLimitWasReached) {
+ maxFrameLimitWasReached = true;
+ LOG.warn("***** OVSDB Frame limit of {} bytes has been reached! *****", this.maxFrameLength);
}
}
import org.opendaylight.ovsdb.lib.notation.Condition;
import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
public class ConditionSerializer extends JsonSerializer<Condition> {
@Override
public void serialize(Condition condition, JsonGenerator generator,
- SerializerProvider provider) throws IOException,
- JsonProcessingException {
+ SerializerProvider provider) throws IOException {
generator.writeStartArray();
generator.writeString(condition.getColumn());
generator.writeString(condition.getFunction().toString());
static SetDeser setDeser = new SetDeser();
static UpdateNotificationDeser unDeser = new UpdateNotificationDeser();
+ private Converter() {
+ // Prevent instantiating a utility class
+ }
+
public static class MapConverter extends StdConverter<JsonNode, OvsdbMap<Object, Object>> {
@Override
public OvsdbMap<Object, Object> convert(JsonNode value) {
static class MapDeser {
public OvsdbMap<Object, Object> deserialize(JsonNode node) {
- if (node.isArray()) {
- if (node.size() == 2) {
- if (node.get(0).isTextual() && "map".equals(node.get(0).asText())) {
- OvsdbMap<Object, Object> map = new OvsdbMap<Object, Object>();
- for (JsonNode pairNode : node.get(1)) {
- if (pairNode.isArray() && node.size() == 2) {
- Object key = atomDeser.deserialize(pairNode.get(0));
- Object value = atomDeser.deserialize(pairNode.get(1));
- map.put(key, value);
- }
+ if (node.isArray() && node.size() == 2) {
+ if (node.get(0).isTextual() && "map".equals(node.get(0).asText())) {
+ OvsdbMap<Object, Object> map = new OvsdbMap<>();
+ for (JsonNode pairNode : node.get(1)) {
+ if (pairNode.isArray() && node.size() == 2) {
+ Object key = atomDeser.deserialize(pairNode.get(0));
+ Object value = atomDeser.deserialize(pairNode.get(1));
+ map.put(key, value);
}
- return map;
- } else if (node.size() == 0) {
- return null;
}
+ return map;
+ } else if (node.size() == 0) {
+ return null;
}
}
- throw new RuntimeException("not a map type");
+ throw new IllegalArgumentException("not a map type");
}
}
static class SetDeser {
public OvsdbSet<Object> deserialize(JsonNode node) {
- OvsdbSet<Object> set = new OvsdbSet<Object>();
+ OvsdbSet<Object> set = new OvsdbSet<>();
if (node.isArray()) {
if (node.size() == 2) {
if (node.get(0).isTextual() && "set".equals(node.get(0).asText())) {
static class UpdateNotificationDeser {
public UpdateNotification deserialize(JsonNode node) {
UpdateNotification un = new UpdateNotification();
- if (node.isArray()) {
- if (node.size() == 2) {
- un.setContext(node.get(0).asText());
- un.setUpdates(node.get(1));
- ObjectMapper objectMapper = new ObjectMapper();
- objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
- TableUpdates updates = objectMapper.convertValue(node.get(1), TableUpdates.class);
- un.setUpdate(updates);
- return un;
- }
+ if (node.isArray() && node.size() == 2) {
+ un.setContext(node.get(0).asText());
+ un.setUpdates(node.get(1));
+ ObjectMapper objectMapper = new ObjectMapper();
+ objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ TableUpdates updates = objectMapper.convertValue(node.get(1), TableUpdates.class);
+ un.setUpdate(updates);
+ return un;
}
return null;
}
}
}
- if (node.isArray() && node.get(0).isTextual()) {
- if ("uuid".equals(node.get(0).asText()) || "named-uuid".equals(node.get(0).asText())) {
- return new UUID(node.get(1).asText());
- }
+ if (node.isArray() && node.get(0).isTextual()
+ && ("uuid".equals(node.get(0).asText()) || "named-uuid".equals(node.get(0).asText()))) {
+ return new UUID(node.get(1).asText());
}
- throw new RuntimeException("not an atom node");
+ throw new IllegalArgumentException("not an atom node");
}
}
}
import org.opendaylight.ovsdb.lib.notation.Mutation;
import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
public class MutationSerializer extends JsonSerializer<Mutation> {
@Override
public void serialize(Mutation condition, JsonGenerator generator,
- SerializerProvider provider) throws IOException,
- JsonProcessingException {
+ SerializerProvider provider) throws IOException {
generator.writeStartArray();
generator.writeString(condition.getColumn());
generator.writeString(condition.getMutator().toString());
import org.opendaylight.ovsdb.lib.notation.OvsdbMap;
import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
public class OvsdbMapSerializer extends JsonSerializer<OvsdbMap<?,?>> {
@Override
public void serialize(OvsdbMap<?,?> map, JsonGenerator generator,
- SerializerProvider provider) throws IOException,
- JsonProcessingException {
+ SerializerProvider provider) throws IOException {
generator.writeStartArray();
generator.writeString("map");
generator.writeStartArray();
import org.opendaylight.ovsdb.lib.notation.OvsdbSet;
import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
public class OvsdbSetSerializer extends JsonSerializer<OvsdbSet<?>> {
@Override
public void serialize(OvsdbSet<?> set, JsonGenerator generator,
- SerializerProvider provider) throws IOException,
- JsonProcessingException {
+ SerializerProvider provider) throws IOException {
generator.writeStartArray();
generator.writeString("set");
generator.writeStartArray();
import org.opendaylight.ovsdb.lib.notation.Row;
import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
public class RowSerializer extends JsonSerializer<Row> {
@Override
public void serialize(Row row, JsonGenerator generator,
- SerializerProvider provider) throws IOException,
- JsonProcessingException {
+ SerializerProvider provider) throws IOException {
generator.writeStartObject();
Collection<Column> columns = row.getColumns();
for (Column<?,?> column : columns) {
import org.opendaylight.ovsdb.lib.notation.UUID;
import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
public class UUIDSerializer extends JsonSerializer<UUID> {
@Override
public void serialize(UUID value, JsonGenerator generator,
- SerializerProvider provider) throws IOException,
- JsonProcessingException {
+ SerializerProvider provider) throws IOException {
generator.writeStartArray();
try {
java.util.UUID.fromString(value.toString());
public class ColumnSchema<E extends TableSchema<E>, D> {
String name;
ColumnType type;
- boolean ephemeral;
- boolean mutable;
public ColumnSchema(String name, ColumnType columnType) {
this.name = name;
/**
* Validates the passed in value against the constraints set for this ColumnSchema
* @param value
- * @throws java.lang.RuntimeException (validation exception)
*/
- public D validate(Object value)throws RuntimeException {
+ public D validate(Object value) {
//todo(type check and validate based on constraints set)
this.type.validate(value);
return (D) value;
}
public Object getNormalizeData(D value) {
- Object untypedValue = null;
+ Object untypedValue;
if (value instanceof Set) {
untypedValue = OvsdbSet.fromSet((Set) value);
} else if (value instanceof Map) {
public AtomicColumnType() {
}
- public AtomicColumnType(BaseType baseType1) {
- super(baseType1);
+ public AtomicColumnType(BaseType baseType) {
+ super(baseType);
}
@Override
if (json.isObject() && json.has("value")) {
return null;
}
- BaseType baseType = BaseType.fromJson(json, "key");
+ BaseType jsonBaseType = BaseType.fromJson(json, "key");
- if (baseType != null) {
+ if (jsonBaseType != null) {
- AtomicColumnType atomicColumnType = new AtomicColumnType(baseType);
+ AtomicColumnType atomicColumnType = new AtomicColumnType(jsonBaseType);
JsonNode node;
if ((node = json.get("min")) != null) {
if (json.isValueNode() || !json.has("value")) {
return null;
}
- BaseType keyType = BaseType.fromJson(json, "key");
+ BaseType jsonKeyType = BaseType.fromJson(json, "key");
BaseType valueType = BaseType.fromJson(json, "value");
- KeyValuedColumnType keyValueColumnType = new KeyValuedColumnType(keyType, valueType);
+ KeyValuedColumnType keyValueColumnType = new KeyValuedColumnType(jsonKeyType, valueType);
JsonNode node;
if ((node = json.get("min")) != null) {
keyValueColumnType.setMin(node.asLong());
@Override
public Object valueFromJson(JsonNode node) {
- if (node.isArray()) {
- if (node.size() == 2) {
- if (node.get(0).isTextual() && "map".equals(node.get(0).asText())) {
- OvsdbMap<Object, Object> map = new OvsdbMap<>();
- for (JsonNode pairNode : node.get(1)) {
- if (pairNode.isArray() && node.size() == 2) {
- Object key = getKeyType().toValue(pairNode.get(0));
- Object value = getBaseType().toValue(pairNode.get(1));
- map.put(key, value);
- }
+ if (node.isArray() && node.size() == 2) {
+ if (node.get(0).isTextual() && "map".equals(node.get(0).asText())) {
+ OvsdbMap<Object, Object> map = new OvsdbMap<>();
+ for (JsonNode pairNode : node.get(1)) {
+ if (pairNode.isArray() && node.size() == 2) {
+ Object key = getKeyType().toValue(pairNode.get(0));
+ Object value = getBaseType().toValue(pairNode.get(1));
+ map.put(key, value);
}
- return map;
- } else if (node.size() == 0) {
- return null;
}
+ return map;
+ } else if (node.size() == 0) {
+ return null;
}
}
return null;
private static final String GETCOLUMN_ENDS_WITH = "Column";
private static final String GETROW_ENDS_WITH = "Row";
+ private TyperUtils() {
+ // Prevent instantiating a utility class
+ }
+
private static <T> String getTableName(Class<T> klazz) {
TypedTable typedTable = klazz.getAnnotation(TypedTable.class);
if (typedTable != null) {
private static boolean isGetTableSchema(Method method) {
TypedColumn typedColumn = method.getAnnotation(TypedColumn.class);
- if (typedColumn != null) {
- return typedColumn.method().equals(MethodType.GETTABLESCHEMA) ? true : false;
- }
- return false;
+ return typedColumn != null && typedColumn.method().equals(MethodType.GETTABLESCHEMA);
}
private static boolean isGetRow(Method method) {
TypedColumn typedColumn = method.getAnnotation(TypedColumn.class);
if (typedColumn != null) {
- return typedColumn.method().equals(MethodType.GETROW) ? true : false;
+ return typedColumn.method().equals(MethodType.GETROW);
}
- if (method.getName().startsWith(GET_STARTS_WITH) && method.getName().endsWith(GETROW_ENDS_WITH)) {
- return true;
- }
- return false;
+ return method.getName().startsWith(GET_STARTS_WITH) && method.getName().endsWith(GETROW_ENDS_WITH);
}
private static boolean isGetColumn(Method method) {
TypedColumn typedColumn = method.getAnnotation(TypedColumn.class);
if (typedColumn != null) {
- return typedColumn.method().equals(MethodType.GETCOLUMN) ? true : false;
+ return typedColumn.method().equals(MethodType.GETCOLUMN);
}
- if (method.getName().startsWith(GET_STARTS_WITH) && method.getName().endsWith(GETCOLUMN_ENDS_WITH)) {
- return true;
- }
- return false;
+ return method.getName().startsWith(GET_STARTS_WITH) && method.getName().endsWith(GETCOLUMN_ENDS_WITH);
}
private static boolean isGetData(Method method) {
TypedColumn typedColumn = method.getAnnotation(TypedColumn.class);
if (typedColumn != null) {
- return typedColumn.method().equals(MethodType.GETDATA) ? true : false;
+ return typedColumn.method().equals(MethodType.GETDATA);
}
- if (method.getName().startsWith(GET_STARTS_WITH) && !method.getName().endsWith(GETCOLUMN_ENDS_WITH)) {
- return true;
- }
- return false;
+ return method.getName().startsWith(GET_STARTS_WITH) && !method.getName().endsWith(GETCOLUMN_ENDS_WITH);
}
private static boolean isSetData(Method method) {
TypedColumn typedColumn = method.getAnnotation(TypedColumn.class);
if (typedColumn != null) {
- return typedColumn.method().equals(MethodType.SETDATA) ? true : false;
+ return typedColumn.method().equals(MethodType.SETDATA);
}
- if (method.getName().startsWith(SET_STARTS_WITH)) {
- return true;
- }
- return false;
+ return method.getName().startsWith(SET_STARTS_WITH);
}
public static Version getColumnFromVersion(Method method) {
}
TypedTable typedTable = klazz.getAnnotation(TypedTable.class);
- if (typedTable != null) {
- if (!dbSchema.getName().equalsIgnoreCase(typedTable.database())) {
- return false;
- }
+ if (typedTable != null && !dbSchema.getName().equalsIgnoreCase(typedTable.database())) {
+ return false;
}
checkTableSchemaVersion(dbSchema, klazz);
}
private static void checkVersion(Version schemaVersion, Version fromVersion, Version untilVersion) {
- if (!fromVersion.equals(Version.NULL)) {
- if (schemaVersion.compareTo(fromVersion) < 0) {
- String message = SchemaVersionMismatchException.createMessage(schemaVersion, fromVersion);
- throw new SchemaVersionMismatchException(message);
- }
+ if (!fromVersion.equals(Version.NULL) && schemaVersion.compareTo(fromVersion) < 0) {
+ String message = SchemaVersionMismatchException.createMessage(schemaVersion, fromVersion);
+ throw new SchemaVersionMismatchException(message);
}
- if (!untilVersion.equals(Version.NULL)) {
- if (schemaVersion.compareTo(untilVersion) > 0) {
- String message = SchemaVersionMismatchException.createMessage(schemaVersion, untilVersion);
- throw new SchemaVersionMismatchException(message);
- }
+ if (!untilVersion.equals(Version.NULL) && schemaVersion.compareTo(untilVersion) > 0) {
+ String message = SchemaVersionMismatchException.createMessage(schemaVersion, untilVersion);
+ throw new SchemaVersionMismatchException(message);
}
}
row.setTableSchema(getTableSchema(dbSchema, klazz));
}
return Reflection.newProxy(klazz, new InvocationHandler() {
- private Object processGetData(Method method) throws Throwable {
+ private Object processGetData(Method method) {
String columnName = getColumnName(method);
checkColumnSchemaVersion(dbSchema, method);
if (columnName == null) {
return row.getColumn(columnSchema).getData();
}
- private Object processGetRow() throws Throwable {
+ private Object processGetRow() {
return row;
}
- private Object processGetColumn(Method method) throws Throwable {
+ private Object processGetColumn(Method method) {
String columnName = getColumnName(method);
checkColumnSchemaVersion(dbSchema, method);
if (columnName == null) {
return row.getColumn(columnSchema);
}
- private Object processSetData(Object proxy, Method method, Object[] args) throws Throwable {
+ private Object processSetData(Object proxy, Method method, Object[] args) {
if (args == null || args.length != 1) {
throw new TyperException("Setter method : " + method.getName() + " requires 1 argument");
}
ColumnSchema<GenericTableSchema, Object> columnSchema =
getColumnSchema(tableSchema, columnName, (Class<Object>) args[0].getClass());
Column<GenericTableSchema, Object> column =
- new Column<GenericTableSchema, Object>(columnSchema, args[0]);
+ new Column<>(columnSchema, args[0]);
row.addColumn(columnName, column);
return proxy;
}
return (args != null
&& args.length == 1
&& method.getName().equals("equals")
- && method.getParameterTypes()[0] == Object.class);
+ && Object.class.equals(method.getParameterTypes()[0]));
}
private Boolean isToStringMethod(Method method, Object[] args) {
return (args == null || args.length == 0) && method.getName().equals("toString");
}
@Override public String toString() {
- String tableName = null;
+ String tableName;
try {
TableSchema<?> schema = (TableSchema<?>)processGetTableSchema();
tableName = schema.getName();
Preconditions.checkNotNull(klazz);
Preconditions.checkNotNull(updates);
Preconditions.checkNotNull(dbSchema);
- Map<UUID,T> result = new HashMap<UUID,T>();
+ Map<UUID,T> result = new HashMap<>();
Map<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> rowUpdates =
extractRowUpdates(klazz,updates,dbSchema);
for (TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema> rowUpdate : rowUpdates.values()) {
- if (rowUpdate != null) {
- if (rowUpdate.getNew() != null) {
- Row<GenericTableSchema> row = rowUpdate.getNew();
- result.put(rowUpdate.getUuid(),TyperUtils.getTypedRowWrapper(dbSchema,klazz,row));
- }
+ if (rowUpdate != null && rowUpdate.getNew() != null) {
+ Row<GenericTableSchema> row = rowUpdate.getNew();
+ result.put(rowUpdate.getUuid(),TyperUtils.getTypedRowWrapper(dbSchema,klazz,row));
}
}
return result;
Preconditions.checkNotNull(klazz);
Preconditions.checkNotNull(updates);
Preconditions.checkNotNull(dbSchema);
- Map<UUID,T> result = new HashMap<UUID,T>();
+ Map<UUID,T> result = new HashMap<>();
Map<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> rowUpdates =
extractRowUpdates(klazz,updates,dbSchema);
for (TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema> rowUpdate : rowUpdates.values()) {
- if (rowUpdate != null) {
- if (rowUpdate.getOld() != null) {
- Row<GenericTableSchema> row = rowUpdate.getOld();
- result.put(rowUpdate.getUuid(),TyperUtils.getTypedRowWrapper(dbSchema,klazz,row));
- }
+ if (rowUpdate != null && rowUpdate.getOld() != null) {
+ Row<GenericTableSchema> row = rowUpdate.getOld();
+ result.put(rowUpdate.getUuid(),TyperUtils.getTypedRowWrapper(dbSchema,klazz,row));
}
}
return result;
Preconditions.checkNotNull(klazz);
Preconditions.checkNotNull(updates);
Preconditions.checkNotNull(dbSchema);
- Map<UUID,T> result = new HashMap<UUID,T>();
+ Map<UUID,T> result = new HashMap<>();
Map<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> rowUpdates =
extractRowUpdates(klazz,updates,dbSchema);
for (TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema> rowUpdate : rowUpdates.values()) {
- if (rowUpdate != null) {
- if (rowUpdate.getNew() == null && rowUpdate.getOld() != null) {
- Row<GenericTableSchema> row = rowUpdate.getOld();
- result.put(rowUpdate.getUuid(),TyperUtils.getTypedRowWrapper(dbSchema,klazz,row));
- }
+ if (rowUpdate != null && rowUpdate.getNew() == null && rowUpdate.getOld() != null) {
+ Row<GenericTableSchema> row = rowUpdate.getOld();
+ result.put(rowUpdate.getUuid(),TyperUtils.getTypedRowWrapper(dbSchema,klazz,row));
}
}
return result;
Preconditions.checkNotNull(updates);
Preconditions.checkNotNull(dbSchema);
Map<UUID, TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> result =
- new HashMap<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>>();
+ new HashMap<>();
TableUpdate<GenericTableSchema> update = updates.getUpdate(TyperUtils.getTableSchema(dbSchema, klazz));
if (update != null) {
Map<UUID, TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> rows = update.getRows();
import org.opendaylight.ovsdb.lib.notation.Row;
import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
import org.opendaylight.ovsdb.lib.schema.GenericTableSchema;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
public class OvsdbRow {
+ private static final Logger LOG = LoggerFactory.getLogger(OvsdbRow.class);
private static final String PARENTUUID = "parent_uuid";
private static final String PARENTTABLE = "parent_table";
private static final String PARENTCOLUMN = "parent_column";
if (rowNode == null) {
return null;
}
- for(Iterator<String> fieldNames = rowNode.fieldNames(); fieldNames.hasNext();) {
+ Iterator<String> fieldNames = rowNode.fieldNames();
+ if (fieldNames.hasNext()) {
String tableName = fieldNames.next();
- Row<GenericTableSchema> row = null;
try {
- row = getRow(client, dbName, tableName, rowNode.get(tableName));
+ Row<GenericTableSchema> row = getRow(client, dbName, tableName, rowNode.get(tableName));
+ return new OvsdbRow(parentTable, parentUuid, parentColumn, tableName, row);
} catch (InterruptedException | ExecutionException | IOException e) {
- e.printStackTrace();
+ LOG.error("Error retrieving the row for {}", tableName, e);
return null;
}
- return new OvsdbRow(parentTable, parentUuid, parentColumn, tableName, row);
}
return null;
}
- public static Row<GenericTableSchema> getRow(OvsdbClient client, String dbName, String tableName, JsonNode rowJson) throws InterruptedException, ExecutionException, JsonParseException, IOException {
+ public static Row<GenericTableSchema> getRow(OvsdbClient client, String dbName, String tableName, JsonNode rowJson) throws InterruptedException, ExecutionException, IOException {
DatabaseSchema dbSchema = client.getSchema(dbName).get();
GenericTableSchema schema = dbSchema.table(tableName, GenericTableSchema.class);
return schema.createRow((ObjectNode)rowJson);
}
}
LOG.debug("createOutputGroupInstructions: addNew {}", addNew);
- if (addNew) {
+ if (addNew && !buckets.getBucket().isEmpty()) {
/* the new output action is not in the bucket, add to bucket */
- if (!buckets.getBucket().isEmpty()) {
- Bucket bucket = buckets.getBucket().get(0);
- List<Action> bucketActionList = Lists.newArrayList();
- bucketActionList.addAll(bucket.getAction());
- /* set order for new action and add to action list */
- ab.setOrder(bucketActionList.size());
- ab.setKey(new ActionKey(bucketActionList.size()));
- bucketActionList.add(ab.build());
-
- /* set bucket and buckets list. Reset groupBuilder with new buckets.*/
- BucketsBuilder bucketsBuilder = new BucketsBuilder();
- List<Bucket> bucketList = Lists.newArrayList();
- BucketBuilder bucketBuilder = new BucketBuilder();
- bucketBuilder.setBucketId(new BucketId((long) 1));
- bucketBuilder.setKey(new BucketKey(new BucketId((long) 1)));
- bucketBuilder.setAction(bucketActionList);
- bucketList.add(bucketBuilder.build());
- bucketsBuilder.setBucket(bucketList);
- groupBuilder.setBuckets(bucketsBuilder.build());
- LOG.debug("createOutputGroupInstructions: bucketList {}", bucketList);
- }
+ Bucket bucket = buckets.getBucket().get(0);
+ List<Action> bucketActionList = Lists.newArrayList();
+ bucketActionList.addAll(bucket.getAction());
+ /* set order for new action and add to action list */
+ ab.setOrder(bucketActionList.size());
+ ab.setKey(new ActionKey(bucketActionList.size()));
+ bucketActionList.add(ab.build());
+
+ /* set bucket and buckets list. Reset groupBuilder with new buckets.*/
+ BucketsBuilder bucketsBuilder = new BucketsBuilder();
+ List<Bucket> bucketList = Lists.newArrayList();
+ BucketBuilder bucketBuilder = new BucketBuilder();
+ bucketBuilder.setBucketId(new BucketId((long) 1));
+ bucketBuilder.setKey(new BucketKey(new BucketId((long) 1)));
+ bucketBuilder.setAction(bucketActionList);
+ bucketList.add(bucketBuilder.build());
+ bucketsBuilder.setBucket(bucketList);
+ groupBuilder.setBuckets(bucketsBuilder.build());
+ LOG.debug("createOutputGroupInstructions: bucketList {}", bucketList);
}
} else {
/* create group */
return serviceRegistry.get(service);
}
- public void start() {
+ public final void start() {
eventHandler.submit(new Runnable() {
@Override
public void run() {
LOG.info(">>>>> dequeue: {}", node);
for (Service service : staticPipeline) {
AbstractServiceInstance serviceInstance = getServiceInstance(service);
- //LOG.info("pipeline: {} - {}", service, serviceInstance);
- if (serviceInstance != null) {
- if (southbound.getBridge(node) != null) {
- serviceInstance.programDefaultPipelineRule(node);
- }
+ if (serviceInstance != null && southbound.getBridge(node) != null) {
+ serviceInstance.programDefaultPipelineRule(node);
}
}
}
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
-import javax.annotation.Nullable;
-
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.ovsdb.openstack.netvirt.api.GatewayMacResolver;
import org.opendaylight.ovsdb.openstack.netvirt.providers.NetvirtProvidersProvider;
import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.AbstractServiceInstance;
import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.Service;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
private SalFlowService flowService;
private final AtomicLong flowCookie = new AtomicLong();
private final ConcurrentMap<Ipv4Address, ArpResolverMetadata> gatewayToArpMetadataMap =
- new ConcurrentHashMap<Ipv4Address, ArpResolverMetadata>();
- private final int ARP_WATCH_BROTHERS = 10;
- private final int WAIT_CYCLES = 3;
- private final int PER_CYCLE_WAIT_DURATION = 1000;
- private final int REFRESH_INTERVAL = 10;
+ new ConcurrentHashMap<>();
+ private static final int ARP_WATCH_BROTHERS = 10;
+ private static final int WAIT_CYCLES = 3;
+ private static final int PER_CYCLE_WAIT_DURATION = 1000;
+ private static final int REFRESH_INTERVAL = 10;
private final ListeningExecutorService arpWatcherWall = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(ARP_WATCH_BROTHERS));
private final ScheduledExecutorService gatewayMacRefresherPool = Executors.newScheduledThreadPool(1);
private final ScheduledExecutorService refreshRequester = Executors.newSingleThreadScheduledExecutor();
* @param sourceMacAddress Source Mac address for the ARP request packet
* @param periodicRefresh Enable/Disable periodic refresh of the Gateway Mac address
* NOTE:Periodic refresh is not supported yet.
- * @param gatewayIp Resolve MAC address of this Gateway Ip
* @return Future object
*/
@Override
});
}
- private static @Nullable Ipv4Address getIPv4Addresses(IpAddress ipAddress) {
- if (ipAddress.getIpv4Address() == null) {
- return null;
- }
- return ipAddress.getIpv4Address();
- }
-
private Flow createArpReplyToControllerFlow(final ArpMessageAddress senderAddress, final Ipv4Address ipForRequestedMac) {
checkNotNull(senderAddress);
checkNotNull(ipForRequestedMac);
arpFlow.setMatch(match);
arpFlow.setInstructions(new InstructionsBuilder().setInstruction(
ImmutableList.of(SEND_TO_CONTROLLER_INSTRUCTION)).build());
- arpFlow.setId(createFlowId(senderAddress, ipForRequestedMac));
+ arpFlow.setId(createFlowId(ipForRequestedMac));
return arpFlow.build();
}
- private FlowId createFlowId(ArpMessageAddress senderAddress, Ipv4Address ipForRequestedMac) {
+ private FlowId createFlowId(Ipv4Address ipForRequestedMac) {
String flowId = ARP_REPLY_TO_CONTROLLER_FLOW_NAME + "|" + ipForRequestedMac.getValue();
return new FlowId(flowId);
}
private void processPortUpdate(Node node, OvsdbTerminationPointAugmentation port) {
LOG.debug("processPortUpdate <{}> <{}>", node, port);
NeutronNetwork network = tenantNetworkManager.getTenantNetwork(port);
- if (network != null ){
- if(!network.getRouterExternal()){
- this.handleInterfaceUpdate(node, port);
- }
+ if (network != null && !network.getRouterExternal()) {
+ this.handleInterfaceUpdate(node, port);
}
}
import org.opendaylight.neutron.spi.NeutronNetwork;
import org.opendaylight.ovsdb.openstack.netvirt.ConfigInterface;
-import org.opendaylight.ovsdb.openstack.netvirt.MdsalHelper;
import org.opendaylight.ovsdb.openstack.netvirt.NetworkHandler;
import org.opendaylight.ovsdb.openstack.netvirt.api.BridgeConfigurationManager;
import org.opendaylight.ovsdb.openstack.netvirt.api.ConfigurationService;
Preconditions.checkNotNull(portNameExt);
if (southbound.isBridgeOnOvsdbNode(ovsdbNode, brExt)) {
- //this would look better if used a method like isNetworkPatchCreated()
- if (isPortOnBridge(bridgeNode, portNameInt)) {
- Node extBridgeNode = southbound.readBridgeNode(ovsdbNode, brExt);
- if (isPortOnBridge(extBridgeNode, portNameExt)) {
- ready = true;
- } else {
- LOG.trace("isNodeL3Ready: node: {}, {} missing",
- bridgeNode, portNameExt);
- }
- } else {
- LOG.trace("isNodeL3Ready: node: {}, {} missing",
- bridgeNode, portNameInt);
- }
+ ready = isNetworkPatchCreated(bridgeNode, southbound.readBridgeNode(ovsdbNode, brExt));
} else {
LOG.trace("isNodeL3Ready: node: {}, {} missing",
bridgeNode, brExt);
/**
* Returns true if a patch port exists between the Integration Bridge and Network Bridge
*/
- private boolean isNetworkPatchCreated(Node node, Node intBridge, Node netBridge) {
+ private boolean isNetworkPatchCreated(Node intBridge, Node netBridge) {
Preconditions.checkNotNull(configurationService);
boolean isPatchCreated = false;
/**
* Creates the Integration Bridge
*/
- private boolean createIntegrationBridge(Node ovsdbNode) throws Exception {
+ private boolean createIntegrationBridge(Node ovsdbNode) {
Preconditions.checkNotNull(configurationService);
if (!addBridge(ovsdbNode, configurationService.getIntegrationBridgeName())) {
return true;
}
- private boolean createExternalBridge(Node ovsdbNode) throws Exception {
+ private boolean createExternalBridge(Node ovsdbNode) {
Preconditions.checkNotNull(configurationService);
if (!addBridge(ovsdbNode, configurationService.getExternalBridgeName())) {
Interface br-int
type: internal
*/
- private boolean createBridges(Node bridgeNode, Node ovsdbNode, NeutronNetwork network) throws Exception {
+ private boolean createBridges(Node bridgeNode, Node ovsdbNode, NeutronNetwork network) {
Preconditions.checkNotNull(configurationService);
Preconditions.checkNotNull(networkingProviderManager);
/**
* Add a Port to a Bridge
*/
- private boolean addPortToBridge (Node node, String bridgeName, String portName) throws Exception {
+ private boolean addPortToBridge (Node node, String bridgeName, String portName) {
boolean rv = true;
if (southbound.extractTerminationPointAugmentation(node, portName) == null) {
/**
* Add a Patch Port to a Bridge
*/
- private boolean addPatchPort (Node node, String bridgeName, String portName, String peerPortName) throws Exception {
+ private boolean addPatchPort (Node node, String bridgeName, String portName, String peerPortName) {
boolean rv = true;
if (southbound.extractTerminationPointAugmentation(node, portName) == null) {
/**
* Add Bridge to a Node
*/
- private boolean addBridge(Node ovsdbNode, String bridgeName) throws Exception {
+ private boolean addBridge(Node ovsdbNode, String bridgeName) {
boolean rv = true;
if ((!southbound.isBridgeOnOvsdbNode(ovsdbNode, bridgeName)) ||
(southbound.getBridgeFromConfig(ovsdbNode, bridgeName) == null)) {
}
private String getControllerIPAddress() {
- InetAddress controllerIP = null;
-
String addressString = ConfigProperties.getProperty(this.getClass(), "ovsdb.controller.address");
if (addressString != null) {
try {
- controllerIP = InetAddress.getByName(addressString);
- if (controllerIP != null) {
+ if (InetAddress.getByName(addressString) != null) {
return addressString;
}
} catch (UnknownHostException e) {
addressString = ConfigProperties.getProperty(this.getClass(), "of.address");
if (addressString != null) {
try {
- controllerIP = InetAddress.getByName(addressString);
- if (controllerIP != null) {
+ if (InetAddress.getByName(addressString) != null) {
return addressString;
}
} catch (UnknownHostException e) {
private volatile GatewayMacResolver gatewayMacResolver;
private class FloatIpData {
- private final Long dpid; // br-int of node where floating ip is associated with tenant port
- private final Long ofPort; // patch port in br-int used to reach br-ex
- private final String segId; // segmentation id of the net where fixed ip is instantiated
- private final String macAddress; // mac address assigned to neutron port of floating ip
+ // br-int of node where floating ip is associated with tenant port
+ private final Long dpid;
+ // patch port in br-int used to reach br-ex
+ private final Long ofPort;
+ // segmentation id of the net where fixed ip is instantiated
+ private final String segId;
+ // mac address assigned to neutron port of floating ip
+ private final String macAddress;
private final String floatingIpAddress;
- private final String fixedIpAddress; // ip address given to tenant vm
+ // ip address given to tenant vm
+ private final String fixedIpAddress;
private final String neutronRouterMac;
FloatIpData(final Long dpid, final Long ofPort, final String segId, final String macAddress,
}else{
NeutronNetwork externalNetwork = neutronNetworkCache.getNetwork(neutronPort.getNetworkUUID());
- if(externalNetwork != null){
- if(externalNetwork.isRouterExternal()){
- final NeutronSubnet externalSubnet = getExternalNetworkSubnet(neutronPort);
- // TODO support IPv6
- if (externalSubnet != null &&
+ if (externalNetwork != null && externalNetwork.isRouterExternal()) {
+ final NeutronSubnet externalSubnet = getExternalNetworkSubnet(neutronPort);
+ // TODO support IPv6
+ if (externalSubnet != null &&
externalSubnet.getIpVersion() == 4) {
- gatewayMacResolver.stopPeriodicRefresh(new Ipv4Address(externalSubnet.getGatewayIP()));
- }
+ gatewayMacResolver.stopPeriodicRefresh(new Ipv4Address(externalSubnet.getGatewayIP()));
}
}
}
for (Neutron_IPs neutronIP : neutronPort.getFixedIPs()) {
NeutronRouter_Interface neutronRouterInterface =
new NeutronRouter_Interface(neutronIP.getSubnetUUID(), neutronPort.getPortUUID());
- neutronRouterInterface.setID(neutronIP.getSubnetUUID()); // id of router interface to be same as subnet
+ // id of router interface to be same as subnet
+ neutronRouterInterface.setID(neutronIP.getSubnetUUID());
neutronRouterInterface.setTenantID(neutronPort.getTenantID());
this.handleNeutronRouterInterfaceEvent(null /*neutronRouter*/, neutronRouterInterface, action);
// need to do this check here because a router interface is not added to a node until tenant becomes needed
// there.
//
- if (!isDelete) {
- if (neutronPort.getFixedIPs() != null) {
- for (Neutron_IPs neutronIP : neutronPort.getFixedIPs()) {
- NeutronRouter_Interface neutronRouterInterface =
+ if (!isDelete && neutronPort.getFixedIPs() != null) {
+ for (Neutron_IPs neutronIP : neutronPort.getFixedIPs()) {
+ NeutronRouter_Interface neutronRouterInterface =
subnetIdToRouterInterfaceCache.get(neutronIP.getSubnetUUID());
- if (neutronRouterInterface != null) {
- this.handleNeutronRouterInterfaceEvent(null /*neutronRouter*/, neutronRouterInterface, action);
- }
+ if (neutronRouterInterface != null) {
+ this.handleNeutronRouterInterfaceEvent(null /*neutronRouter*/, neutronRouterInterface, action);
}
}
}
// this.programFlowsForFloatingIP(neutronFloatingIP, action == Action.DELETE);
if (action != Action.DELETE) {
- programFlowsForFloatingIPArpAdd(neutronFloatingIP); // must be first, as it updates floatIpDataMapCache
+ // must be first, as it updates floatIpDataMapCache
+ programFlowsForFloatingIPArpAdd(neutronFloatingIP);
programFlowsForFloatingIPInbound(neutronFloatingIP, Action.ADD);
programFlowsForFloatingIPOutbound(neutronFloatingIP, Action.ADD);
programFlowsForFloatingIPOutbound(neutronFloatingIP, Action.DELETE);
programFlowsForFloatingIPInbound(neutronFloatingIP, Action.DELETE);
- programFlowsForFloatingIPArpDelete(neutronFloatingIP.getID()); // must be last, as it updates floatIpDataMapCache
+ // must be last, as it updates floatIpDataMapCache
+ programFlowsForFloatingIPArpDelete(neutronFloatingIP.getID());
}
}
// will look at desired action for node.
final String cacheKey = node.getNodeId().getValue() + ":" + providerSegmentationId + ":" + ipStr;
- final Boolean isProgrammed = l3ForwardingCache.contains(cacheKey);
+ final boolean isProgrammed = l3ForwardingCache.contains(cacheKey);
- if (actionForNode == Action.DELETE && isProgrammed == Boolean.FALSE) {
+ if (actionForNode == Action.DELETE && !isProgrammed) {
LOG.trace("programL3ForwardingStage1 for node {} providerId {} mac {} ip {} action {} is already done",
node.getNodeId().getValue(), providerSegmentationId, macAddress, ipStr, actionForNode);
return;
}
- if (actionForNode == Action.ADD && isProgrammed == Boolean.TRUE) {
+ if (actionForNode == Action.ADD && isProgrammed) {
LOG.trace("programL3ForwardingStage1 for node {} providerId {} mac {} ip {} action {} is already done",
node.getNodeId().getValue(), providerSegmentationId, macAddress, ipStr, actionForNode);
return;
final String cacheKey = node.getNodeId().getValue() + ":" +
sourceSegmentationId + ":" + destinationSegmentationId + ":" +
ipStr + "/" + Integer.toString(mask);
- final Boolean isProgrammed = routerInterfacesCache.contains(cacheKey);
+ final boolean isProgrammed = routerInterfacesCache.contains(cacheKey);
- if (actionForNode == Action.DELETE && isProgrammed == Boolean.FALSE) {
+ if (actionForNode == Action.DELETE && !isProgrammed) {
LOG.trace("programRouterInterfaceStage1 for node {} sourceSegId {} destSegId {} mac {} ip {} mask {}" +
" action {} is already done",
node.getNodeId().getValue(), sourceSegmentationId, destinationSegmentationId,
macAddress, ipStr, mask, actionForNode);
return;
}
- if (actionForNode == Action.ADD && isProgrammed == Boolean.TRUE) {
+ if (actionForNode == Action.ADD && isProgrammed) {
LOG.trace("programRouterInterfaceStage1 for node {} sourceSegId {} destSegId {} mac {} ip {} mask {}" +
" action {} is already done",
node.getNodeId().getValue(), sourceSegmentationId, destinationSegmentationId,
// will look at desired action for node.
//
final String cacheKey = dpid + ":" + segOrOfPort + ":" + ipStr;
- final Boolean isProgrammed = staticArpEntryCache.contains(cacheKey);
+ final boolean isProgrammed = staticArpEntryCache.contains(cacheKey);
- if (action == Action.DELETE && isProgrammed == Boolean.FALSE) {
+ if (action == Action.DELETE && !isProgrammed) {
LOG.trace("programStaticArpStage1 dpid {} segOrOfPort {} mac {} ip {} action {} is already done",
dpid, segOrOfPort, macAddress, ipStr, action);
return true;
}
- if (action == Action.ADD && isProgrammed == Boolean.TRUE) {
+ if (action == Action.ADD && isProgrammed) {
LOG.trace("programStaticArpStage1 dpid {} segOrOfPort {} mac {} ip {} action {} is already done",
dpid, segOrOfPort, macAddress, ipStr, action);
return true;
// will look at desired action for node.
//
final String cacheKey = dpid + ":" + inboundOFPort + ":" + providerSegmentationId + ":" + matchAddress;
- final Boolean isProgrammed = inboundIpRewriteCache.contains(cacheKey);
+ final boolean isProgrammed = inboundIpRewriteCache.contains(cacheKey);
- if (action == Action.DELETE && isProgrammed == Boolean.FALSE) {
+ if (action == Action.DELETE && !isProgrammed) {
LOG.trace("programInboundIpRewriteStage1 dpid {} OFPort {} seg {} matchAddress {} rewriteAddress {}" +
" action {} is already done",
dpid, inboundOFPort, providerSegmentationId, matchAddress, rewriteAddress, action);
return true;
}
- if (action == Action.ADD && isProgrammed == Boolean.TRUE) {
+ if (action == Action.ADD && isProgrammed) {
LOG.trace("programInboundIpRewriteStage1 dpid {} OFPort {} seg {} matchAddress {} rewriteAddress {}" +
" action is already done",
dpid, inboundOFPort, providerSegmentationId, matchAddress, rewriteAddress, action);
// will look at desired action for node.
//
final String cacheKey = node.getNodeId().getValue() + ":" + providerSegmentationId + ":" + cidr;
- final Boolean isProgrammed = outboundIpRewriteExclusionCache.contains(cacheKey);
+ final boolean isProgrammed = outboundIpRewriteExclusionCache.contains(cacheKey);
- if (actionForRewriteExclusion == Action.DELETE && isProgrammed == Boolean.FALSE) {
+ if (actionForRewriteExclusion == Action.DELETE && !isProgrammed) {
LOG.trace("programIpRewriteExclusionStage1 node {} providerId {} cidr {} action {} is already done",
node.getNodeId().getValue(), providerSegmentationId, cidr, actionForRewriteExclusion);
return;
}
- if (actionForRewriteExclusion == Action.ADD && isProgrammed == Boolean.TRUE) {
+ if (actionForRewriteExclusion == Action.ADD && isProgrammed) {
LOG.trace("programIpRewriteExclusionStage1 node {} providerId {} cidr {} action {} is already done",
node.getNodeId().getValue(), providerSegmentationId, cidr, actionForRewriteExclusion);
return;
// will look at desired action for node.
//
final String cacheKey = fid.dpid + ":" + fid.segId + ":" + fid.fixedIpAddress;
- final Boolean isProgrammed = outboundIpRewriteCache.contains(cacheKey);
+ final boolean isProgrammed = outboundIpRewriteCache.contains(cacheKey);
- if (action == Action.DELETE && isProgrammed == Boolean.FALSE) {
+ if (action == Action.DELETE && !isProgrammed) {
LOG.trace("programOutboundIpRewriteStage1 dpid {} seg {} fixedIpAddress {} floatIp {} action {} " +
"is already done",
fid.dpid, fid.segId, fid.fixedIpAddress, fid.floatingIpAddress, action);
return;
}
- if (action == Action.ADD && isProgrammed == Boolean.TRUE) {
+ if (action == Action.ADD && isProgrammed) {
LOG.trace("programOutboundIpRewriteStage1 dpid {} seg {} fixedIpAddress {} floatIp {} action {} " +
"is already done",
fid.dpid, fid.segId, fid.fixedIpAddress, fid.floatingIpAddress, action);
Constants.EXTERNAL_ID_INTERFACE_ID);
if (null != portId) {
NeutronPort port = neutronPortCache.getPort(portId);
- if (null != port) {
- if (!(port.getID().equals(neutronPort.getID()))
- && port.getDeviceOwner().contains("compute")) {
- List<Neutron_IPs> portFixedIp = port.getFixedIPs();
- if (null == portFixedIp || portFixedIp.isEmpty()) {
- return false;
- }
- if (portFixedIp.iterator().next().getSubnetUUID()
- .equals(neutronPort.getFixedIPs().iterator().next().getSubnetUUID())) {
- LOG.trace("isLastPortinSubnet: Port is not the only port.");
- return false;
- }
+ if (null != port && !(port.getID().equals(neutronPort.getID()))
+ && port.getDeviceOwner().contains("compute")) {
+ List<Neutron_IPs> portFixedIp = port.getFixedIPs();
+ if (null == portFixedIp || portFixedIp.isEmpty()) {
+ return false;
+ }
+ if (portFixedIp.iterator().next().getSubnetUUID()
+ .equals(neutronPort.getFixedIPs().iterator().next().getSubnetUUID())) {
+ LOG.trace("isLastPortinSubnet: Port is not the only port.");
+ return false;
}
}
}
for (TerminationPoint tp : terminationPoints) {
OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation =
tp.getAugmentation(OvsdbTerminationPointAugmentation.class);
- if (null != ovsdbTerminationPointAugmentation) {
- if (!(ovsdbTerminationPointAugmentation.getName().equals(Constants.INTEGRATION_BRIDGE))
- && !(terminationPointAugmentation.getInterfaceUuid()
- .equals(ovsdbTerminationPointAugmentation.getInterfaceUuid()))) {
- LOG.debug("isLastPortinBridge: it the last port in bridge {}",
- terminationPointAugmentation.getName());
- return false;
- }
+ if (null != ovsdbTerminationPointAugmentation
+ && !(ovsdbTerminationPointAugmentation.getName().equals(Constants.INTEGRATION_BRIDGE))
+ && !(terminationPointAugmentation.getInterfaceUuid()
+ .equals(ovsdbTerminationPointAugmentation.getInterfaceUuid()))) {
+ LOG.debug("isLastPortinBridge: it the last port in bridge {}",
+ terminationPointAugmentation.getName());
+ return false;
}
}
}
private static InstanceIdentifierCodec instanceIdentifierCodec;
+ private SouthboundUtil() {
+ // Prevent instantiating a utility class
+ }
+
public static void setInstanceIdentifierCodec(InstanceIdentifierCodec iidc) {
instanceIdentifierCodec = iidc;
}
Optional<Node> optional = nf.get();
if (optional != null && optional.isPresent()) {
OvsdbNodeAugmentation ovsdbNode = null;
- if (optional.get() instanceof Node) {
- ovsdbNode = optional.get().getAugmentation(OvsdbNodeAugmentation.class);
- } else if (optional.get() instanceof OvsdbNodeAugmentation) {
- ovsdbNode = (OvsdbNodeAugmentation) optional.get();
+ Node node = optional.get();
+ if (node instanceof OvsdbNodeAugmentation) {
+ ovsdbNode = (OvsdbNodeAugmentation) node;
+ } else if (node != null) {
+ ovsdbNode = node.getAugmentation(OvsdbNodeAugmentation.class);
}
if (ovsdbNode != null) {
return Optional.of(ovsdbNode);
try {
for (Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces();
ifaces.hasMoreElements();) {
- NetworkInterface iface = (NetworkInterface) ifaces.nextElement();
+ NetworkInterface iface = ifaces.nextElement();
for (Enumeration<InetAddress> inetAddrs = iface.getInetAddresses(); inetAddrs.hasMoreElements();) {
- InetAddress inetAddr = (InetAddress) inetAddrs.nextElement();
- if (!inetAddr.isLoopbackAddress()) {
- if (inetAddr.isSiteLocalAddress()) {
- ipaddress = inetAddr.getHostAddress();
- break;
- }
+ InetAddress inetAddr = inetAddrs.nextElement();
+ if (!inetAddr.isLoopbackAddress() && inetAddr.isSiteLocalAddress()) {
+ ipaddress = inetAddr.getHostAddress();
+ break;
}
}
}