2 * Copyright (c) 2016 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
9 package org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.util;
11 import java.util.List;
13 import org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.SocketInfo;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.hostconfig.rev150712.hostconfig.attributes.hostconfigs.Hostconfig;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.hostconfig.rev150712.hostconfig.attributes.hostconfigs.HostconfigBuilder;
16 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
18 import com.google.common.base.Preconditions;
19 import com.google.common.collect.Lists;
20 import com.google.gson.JsonArray;
21 import com.google.gson.JsonObject;
24 public class HostconfigUtil {
26 public static final String L2_HOST_TYPE = "ODL L2";
27 private static final String VHOST_USER = "vhostuser";
28 private static final String VNIC_TYPE = "normal";
29 private static final String HAS_DATAPATH_TYPE_NETDEV = "False";
30 private static final String SUPPORT_VHOST_USER = "True";
31 private static final String VHOSTUSER_MODE = "server";
32 private static final List<String> supportedNetworkTypes = Lists.newArrayList("local", "vlan", "vxlan", "gre");
34 public static Hostconfig createHostconfigsDataFor(NodeId nodeId, SocketInfo socketInfo) {
35 Preconditions.checkNotNull(nodeId);
36 Preconditions.checkNotNull(socketInfo);
37 JsonObject odlL2 = new JsonObject();
38 odlL2.add("allowed_network_types", buildSupportedNetworkTypes());
39 odlL2.add("supported_vnic_types", buildSupportedVnicTypes(socketInfo));
40 return new HostconfigBuilder().setHostId(nodeId.getValue())
41 .setHostType(L2_HOST_TYPE)
42 .setConfig(odlL2.toString())
46 private static JsonArray buildSupportedNetworkTypes() {
47 JsonArray networkTypes = new JsonArray();
48 supportedNetworkTypes.forEach(networkTypes::add);
52 private static JsonArray buildSupportedVnicTypes(SocketInfo socketInfo) {
53 JsonArray supportedVnicTypes = new JsonArray();
54 JsonObject supportedVnicType = new JsonObject();
55 supportedVnicType.addProperty("vnic_type", VNIC_TYPE);
56 supportedVnicType.addProperty("vif_type", VHOST_USER);
57 supportedVnicType.add("vif_details", buildVifDetails(socketInfo));
58 supportedVnicTypes.add(supportedVnicType);
59 return supportedVnicTypes;
62 private static JsonObject buildVifDetails(SocketInfo socketInfo) {
63 JsonObject vifDetails = new JsonObject();
64 vifDetails.addProperty("has_datapath_type_netdev", HAS_DATAPATH_TYPE_NETDEV);
65 vifDetails.addProperty("support_vhost_user", SUPPORT_VHOST_USER);
66 vifDetails.addProperty("port_prefix", socketInfo.getSocketPrefix());
67 vifDetails.addProperty("vhostuser_socket_dir", socketInfo.getSocketPath());
68 vifDetails.addProperty("vhostuser_mode", VHOSTUSER_MODE);
69 vifDetails.addProperty("vhostuser_socket", socketInfo.getVhostUserSocket());