use of org.onosproject.ovsdb.rfc.notation.OvsdbMap in project onos by opennetworkinglab.
the class DefaultOpenstackNodeHandler method isDpdkIntfsCreated.
private boolean isDpdkIntfsCreated(OpenstackNode osNode, Collection<DpdkInterface> dpdkInterfaces) {
OvsdbClientService client = getOvsdbClient(osNode, ovsdbPortNum, ovsdbController);
if (client == null) {
log.info("Failed to get ovsdb client");
return false;
}
Set<OvsdbPort> ports = client.getPorts();
for (DpdkInterface dpdkIntf : dpdkInterfaces) {
Optional<OvsdbPort> port = ports.stream().filter(ovsdbPort -> ovsdbPort.portName().value().equals(dpdkIntf.intf())).findAny();
if (!port.isPresent()) {
return false;
}
Interface intf = client.getInterface(dpdkIntf.intf());
if (intf == null) {
return false;
}
OvsdbSet mtu = (OvsdbSet) intf.getMtuColumn().data();
if (mtu == null) {
return false;
}
OvsdbMap option = (OvsdbMap) intf.getOptionsColumn().data();
if (option == null) {
return false;
}
if (!mtu.set().contains(dpdkIntf.mtu().intValue()) || !option.toString().contains(dpdkIntf.pciAddress())) {
log.trace("The dpdk interface {} was created but mtu or " + "pci address is different from the config.");
return false;
}
}
return true;
}
use of org.onosproject.ovsdb.rfc.notation.OvsdbMap in project onos by opennetworkinglab.
the class DefaultOvsdbClient method createQos.
@Override
public boolean createQos(OvsdbQos ovsdbQos) {
DatabaseSchema dbSchema = schema.get(DATABASENAME);
Qos qos = (Qos) TableGenerator.createTable(dbSchema, OvsdbTable.QOS);
OvsdbRowStore rowStore = getRowStore(DATABASENAME, QOS);
if (rowStore == null) {
log.debug("The qos uuid is null");
return false;
}
ArrayList<Operation> operations = Lists.newArrayList();
Set<String> types = Sets.newHashSet();
Map<Long, Uuid> queues = Maps.newHashMap();
types.add(ovsdbQos.qosType());
qos.setOtherConfig(ovsdbQos.otherConfigs());
qos.setExternalIds(ovsdbQos.externalIds());
qos.setType(types);
if (ovsdbQos.qosQueues().isPresent()) {
for (Map.Entry<Long, String> entry : ovsdbQos.qosQueues().get().entrySet()) {
OvsdbRowStore queueRowStore = getRowStore(DATABASENAME, QUEUE);
if (queueRowStore != null) {
ConcurrentMap<String, Row> queueTableRows = queueRowStore.getRowStore();
Row queueRow = queueTableRows.values().stream().filter(r -> {
OvsdbMap ovsdbMap = (OvsdbMap) (r.getColumn(EXTERNAL_ID).data());
return entry.getValue().equals(ovsdbMap.map().get(QUEUE_EXTERNAL_ID_KEY));
}).findFirst().orElse(null);
if (queueRow != null) {
queues.put(entry.getKey(), queueRow.uuid());
}
}
}
qos.setQueues(queues);
}
Insert qosInsert = new Insert(dbSchema.getTableSchema(QOS), QOS, qos.getRow());
operations.add(qosInsert);
try {
transactConfig(DATABASENAME, operations).get();
} catch (InterruptedException | ExecutionException e) {
return false;
}
return true;
}
use of org.onosproject.ovsdb.rfc.notation.OvsdbMap in project onos by opennetworkinglab.
the class DefaultOvsdbClient method bindQueues.
@Override
public void bindQueues(QosId qosId, Map<Long, QueueDescription> queues) {
DatabaseSchema dbSchema = schema.get(DATABASENAME);
OvsdbRowStore qosRowStore = getRowStore(DATABASENAME, QOS);
if (qosRowStore == null) {
log.debug("The qos uuid is null");
return;
}
OvsdbRowStore queueRowStore = getRowStore(DATABASENAME, QUEUE);
if (queueRowStore == null) {
log.debug("The queue uuid is null");
return;
}
ConcurrentMap<String, Row> qosTableRows = qosRowStore.getRowStore();
ConcurrentMap<String, Row> queueTableRows = queueRowStore.getRowStore();
Row qosRow = qosTableRows.values().stream().filter(r -> {
OvsdbMap ovsdbMap = (OvsdbMap) (r.getColumn(EXTERNAL_ID).data());
return qosId.name().equals(ovsdbMap.map().get(QOS_EXTERNAL_ID_KEY));
}).findFirst().orElse(null);
if (qosRow == null) {
log.warn("Can't find QoS {}", qosId);
return;
}
Uuid qosUuid = qosRow.uuid();
Map<Long, Uuid> newQueues = new HashMap<>();
for (Map.Entry<Long, QueueDescription> entry : queues.entrySet()) {
Row queueRow = queueTableRows.values().stream().filter(r -> {
OvsdbMap ovsdbMap = (OvsdbMap) (r.getColumn(EXTERNAL_ID).data());
return entry.getValue().queueId().name().equals(ovsdbMap.map().get(QUEUE_EXTERNAL_ID_KEY));
}).findFirst().orElse(null);
if (queueRow != null) {
newQueues.put(entry.getKey(), queueRow.uuid());
}
}
// update the qos table
ArrayList<Operation> operations = Lists.newArrayList();
Condition condition = ConditionUtil.isEqual(UUID, qosUuid);
Mutation mutation = MutationUtil.insert(QUEUES, newQueues);
List<Condition> conditions = Collections.singletonList(condition);
List<Mutation> mutations = Collections.singletonList(mutation);
operations.add(new Mutate(dbSchema.getTableSchema(QOS), conditions, mutations));
transactConfig(DATABASENAME, operations);
}
use of org.onosproject.ovsdb.rfc.notation.OvsdbMap in project onos by opennetworkinglab.
the class DefaultOvsdbClient method applyQos.
@Override
public void applyQos(PortNumber portNumber, String qosName) {
DatabaseSchema dbSchema = schema.get(DATABASENAME);
OvsdbRowStore portRowStore = getRowStore(DATABASENAME, PORT);
if (portRowStore == null) {
log.debug("The port uuid is null");
return;
}
OvsdbRowStore qosRowStore = getRowStore(DATABASENAME, QOS);
if (qosRowStore == null) {
log.debug("The qos uuid is null");
return;
}
// Due to Qos Table doesn't have a unique identifier except uuid, unlike
// Bridge or Port Table has a name column,in order to make the api more
// general, put qos name in external_ids column of Qos Table if this qos
// created by onos.
ConcurrentMap<String, Row> qosTableRows = qosRowStore.getRowStore();
ConcurrentMap<String, Row> portTableRows = portRowStore.getRowStore();
Row qosRow = qosTableRows.values().stream().filter(r -> {
OvsdbMap ovsdbMap = (OvsdbMap) (r.getColumn(EXTERNAL_ID).data());
return qosName.equals(ovsdbMap.map().get(QOS_EXTERNAL_ID_KEY));
}).findFirst().orElse(null);
Row portRow = portTableRows.values().stream().filter(r -> r.getColumn("name").data().equals(portNumber.name())).findFirst().orElse(null);
if (portRow != null && qosRow != null) {
String qosId = qosRow.uuid().value();
Uuid portUuid = portRow.uuid();
Map<String, Column> columns = new HashMap<>();
Row newPortRow = new Row(PORT, portUuid, columns);
Port newport = new Port(dbSchema, newPortRow);
columns.put(Port.PortColumn.QOS.columnName(), newport.getQosColumn());
newport.setQos(Uuid.uuid(qosId));
updateConfig(PORT, UUID, portUuid.value(), newport.getRow());
}
}
use of org.onosproject.ovsdb.rfc.notation.OvsdbMap in project onos by opennetworkinglab.
the class TransValueUtil method getValueFromKvType.
/**
* Convert KeyValuedColumnType JsonNode into OvsdbMap value.
* @param json KeyValuedColumnType JsonNode
* @param kvType KeyValuedColumnType entity
* @return Object OvsdbMap
*/
private static Object getValueFromKvType(JsonNode json, KeyValuedColumnType kvType) {
if (json.isArray()) {
if (json.size() == 2) {
if (json.get(0).isTextual() && "map".equals(json.get(0).asText())) {
Map map = Maps.newHashMap();
for (JsonNode pairNode : json.get(1)) {
if (pairNode.isArray() && json.size() == 2) {
Object key = transToValue(pairNode.get(0), kvType.keyType());
Object value = transToValue(pairNode.get(1), kvType.valueType());
map.put(key, value);
}
}
return OvsdbMap.ovsdbMap(map);
}
}
}
return null;
}
Aggregations