+
+ public static DatapathId createDatapathId(Bridge bridge) {
+ Preconditions.checkNotNull(bridge);
+ if (bridge.getDatapathIdColumn() == null) {
+ return null;
+ } else {
+ return createDatapathId(bridge.getDatapathIdColumn().getData());
+ }
+ }
+
+ public static DatapathId createDatapathId(Set<String> dpids) {
+ Preconditions.checkNotNull(dpids);
+ if (dpids.isEmpty()) {
+ return null;
+ } else {
+ String[] dpidArray = new String[dpids.size()];
+ dpids.toArray(dpidArray);
+ return createDatapathId(dpidArray[0]);
+ }
+ }
+
+ public static String createDatapathType(OvsdbBridgeAugmentation mdsalbridge) {
+ String datapathtype = new String(SouthboundConstants.DATAPATH_TYPE_MAP.get(DatapathTypeSystem.class));
+
+ if (mdsalbridge.getDatapathType() != null) {
+ if (SouthboundConstants.DATAPATH_TYPE_MAP.get(mdsalbridge.getDatapathType()) != null) {
+ datapathtype = SouthboundConstants.DATAPATH_TYPE_MAP.get(mdsalbridge.getDatapathType());
+ } else {
+ throw new IllegalArgumentException("Unknown datapath type "
+ + SouthboundConstants.DATAPATH_TYPE_MAP.get(mdsalbridge.getDatapathType()));
+ }
+ }
+ return datapathtype;
+ }
+
+ public static Class<? extends DatapathTypeBase> createDatapathType(String type) {
+ Preconditions.checkNotNull(type);
+ if (type.isEmpty()) {
+ return DatapathTypeSystem.class;
+ } else {
+ ImmutableBiMap<String, Class<? extends DatapathTypeBase>> mapper =
+ SouthboundConstants.DATAPATH_TYPE_MAP.inverse();
+ return mapper.get(type);
+ }
+ }
+
+ public static DatapathId createDatapathId(String dpid) {
+ Preconditions.checkNotNull(dpid);
+ DatapathId datapath;
+ if (dpid.matches("^[0-9a-fA-F]{16}")) {
+ Splitter splitter = Splitter.fixedLength(2);
+ Joiner joiner = Joiner.on(":");
+ datapath = new DatapathId(joiner.join(splitter.split(dpid)));
+ } else {
+ datapath = new DatapathId(dpid);
+ }
+ return datapath;
+ }
+
+ public static Set<String> createOvsdbBridgeProtocols(OvsdbBridgeAugmentation ovsdbBridgeNode) {
+ Set<String> protocols = new HashSet<String>();
+ if (ovsdbBridgeNode.getProtocolEntry() != null && ovsdbBridgeNode.getProtocolEntry().size() > 0) {
+ for (ProtocolEntry protocol : ovsdbBridgeNode.getProtocolEntry()) {
+ if (SouthboundConstants.OVSDB_PROTOCOL_MAP.get(protocol.getProtocol()) != null) {
+ protocols.add(SouthboundConstants.OVSDB_PROTOCOL_MAP.get(protocol.getProtocol()));
+ } else {
+ throw new IllegalArgumentException("Unknown protocol " + protocol.getProtocol());
+ }
+ }
+ }
+ return protocols;
+ }
+
+ public static Class<? extends InterfaceTypeBase> createInterfaceType(String type) {
+ Preconditions.checkNotNull(type);
+ return SouthboundConstants.OVSDB_INTERFACE_TYPE_MAP.get(type);
+ }
+
+ public static String createOvsdbInterfaceType(Class<? extends InterfaceTypeBase> mdsaltype) {
+ Preconditions.checkNotNull(mdsaltype);
+ ImmutableBiMap<Class<? extends InterfaceTypeBase>, String> mapper =
+ SouthboundConstants.OVSDB_INTERFACE_TYPE_MAP.inverse();
+ return mapper.get(mdsaltype);
+ }
+
+ public static List<ProtocolEntry> createMdsalProtocols(Bridge bridge) {
+ Set<String> protocols = bridge.getProtocolsColumn().getData();
+ List<ProtocolEntry> protocolList = new ArrayList<ProtocolEntry>();
+ if (protocols != null && protocols.size() > 0) {
+ ImmutableBiMap<String, Class<? extends OvsdbBridgeProtocolBase>> mapper =
+ SouthboundConstants.OVSDB_PROTOCOL_MAP.inverse();
+ for (String protocol : protocols) {
+ if (protocol != null && mapper.get(protocol) != null) {
+ protocolList.add(new ProtocolEntryBuilder().
+ setProtocol((Class<? extends OvsdbBridgeProtocolBase>) mapper.get(protocol)).build());
+ }
+ }
+ }
+ return protocolList;
+ }
+
+ public static List<ControllerEntry> createControllerEntries(Bridge bridge,Map<UUID,
+ Controller> updatedControllerRows) {
+ LOG.debug("Bridge: {}, updatedControllerRows: {}",bridge,updatedControllerRows);
+ Set<UUID> controllerUUIDs = bridge.getControllerColumn().getData();
+ List<ControllerEntry> controllerEntries = new ArrayList<ControllerEntry>();
+ for (UUID controllerUUID : controllerUUIDs ) {
+ Controller controller = updatedControllerRows.get(controllerUUID);
+ if (controller != null && controller.getTargetColumn() != null
+ && controller.getTargetColumn() != null) {
+ String targetString = controller.getTargetColumn().getData();
+ controllerEntries.add(new ControllerEntryBuilder().setTarget(new Uri(targetString)).build());
+ }
+ }
+ return controllerEntries;
+ }
+
+ public static Map<UUID, Controller> createOvsdbController(OvsdbBridgeAugmentation omn,DatabaseSchema dbSchema) {
+ List<ControllerEntry> controllerEntries = omn.getControllerEntry();
+ Map<UUID,Controller> controllerMap = new HashMap<UUID,Controller>();
+ if (controllerEntries != null && !controllerEntries.isEmpty()) {
+ int index = 0;
+ for (ControllerEntry controllerEntry : controllerEntries) {
+ String controllerNamedUUID = "Controller_" + getRandomUUID();
+ Controller controller = TyperUtils.getTypedRowWrapper(dbSchema, Controller.class);
+ controller.setTarget(controllerEntry.getTarget().getValue());
+ controllerMap.put(new UUID(controllerNamedUUID), controller);
+ }
+ }
+ return controllerMap;
+ }
+
+ public static String getRandomUUID() {
+ return java.util.UUID.randomUUID().toString().replace("-", "");
+ }