2 * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.neutron.hostconfig.vpp;
10 import com.google.common.base.Preconditions;
11 import com.google.common.collect.Lists;
12 import com.google.gson.JsonArray;
13 import com.google.gson.JsonObject;
14 import java.util.HashMap;
15 import java.util.List;
17 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
19 public final class HostconfigUtil {
21 static final String L2_HOST_TYPE = "ODL L2";
22 private static final String VHOST_USER = "vhostuser";
23 private static final String VNIC_TYPE = "normal";
24 private static final String HAS_DATAPATH_TYPE_NETDEV = "False";
25 private static final String SUPPORT_VHOST_USER = "True";
26 private static final List<String> SUPPORTED_NET_TYPES = Lists.newArrayList("local", "vlan", "vxlan", "gre");
28 private HostconfigUtil() {
31 public static Map<String, String> createHostconfigsDataFor(NodeId nodeId, SocketInfo socketInfo) {
32 Preconditions.checkNotNull(nodeId);
33 Preconditions.checkNotNull(socketInfo);
34 JsonObject odlL2 = new JsonObject();
35 odlL2.add("allowed_network_types", buildSupportedNetworkTypes());
36 odlL2.add("supported_vnic_types", buildSupportedVnicTypes(socketInfo));
37 Map<String, String> hostConfigs = new HashMap<>();
38 hostConfigs.put(L2_HOST_TYPE, odlL2.toString());
42 private static JsonArray buildSupportedNetworkTypes() {
43 JsonArray networkTypes = new JsonArray();
44 SUPPORTED_NET_TYPES.forEach(networkTypes::add);
48 private static JsonArray buildSupportedVnicTypes(SocketInfo socketInfo) {
49 JsonObject supportedVnicType = new JsonObject();
50 supportedVnicType.addProperty("vnic_type", VNIC_TYPE);
51 supportedVnicType.addProperty("vif_type", VHOST_USER);
52 supportedVnicType.add("vif_details", buildVifDetails(socketInfo));
53 JsonArray supportedVnicTypes = new JsonArray();
54 supportedVnicTypes.add(supportedVnicType);
55 return supportedVnicTypes;
58 private static JsonObject buildVifDetails(SocketInfo socketInfo) {
59 JsonObject vifDetails = new JsonObject();
60 vifDetails.addProperty("has_datapath_type_netdev", HAS_DATAPATH_TYPE_NETDEV);
61 vifDetails.addProperty("support_vhost_user", SUPPORT_VHOST_USER);
62 vifDetails.addProperty("port_prefix", socketInfo.getSocketPrefix());
63 vifDetails.addProperty("vhostuser_socket_dir", socketInfo.getSocketPath());
64 vifDetails.addProperty("vhostuser_mode", socketInfo.getVhostuserMode());
65 vifDetails.addProperty("vhostuser_socket", socketInfo.getVhostUserSocket());