2 * Copyright (c) 2016 Cisco Systems. 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.renderer.vpp.commands;
11 import com.google.common.base.Preconditions;
12 import com.google.common.base.Strings;
13 import org.opendaylight.groupbasedpolicy.renderer.vpp.util.General;
14 import org.opendaylight.groupbasedpolicy.renderer.vpp.util.General.Operations;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.VhostUserRole;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.VppInterfaceAugmentation;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.VppInterfaceAugmentationBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.interfaces._interface.L2Builder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.interfaces._interface.RoutingBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.interfaces._interface.VhostUserBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.l2.base.attributes.interconnection.BridgeBasedBuilder;
26 public class VhostUserCommand extends AbstractInterfaceCommand {
28 private String socket;
29 private VhostUserRole role;
31 private VhostUserCommand(VhostUserCommandBuilder builder) {
32 this.name = builder.getName();
33 this.operation = builder.getOperation();
34 this.socket = builder.getSocket();
35 this.role = builder.getRole();
36 this.enabled = builder.isEnabled();
37 this.description = builder.getDescription();
38 this.bridgeDomain = builder.getBridgeDomain();
39 this.enableProxyArp = builder.getEnableProxyArp();
43 public static VhostUserCommandBuilder builder() {
44 return new VhostUserCommandBuilder();
47 public String getSocket() {
51 public VhostUserRole getRole() {
56 public InterfaceBuilder getInterfaceBuilder() {
57 InterfaceBuilder interfaceBuilder =
58 new InterfaceBuilder().setKey(new InterfaceKey(name))
60 .setDescription(description)
62 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.VhostUser.class)
64 .setLinkUpDownTrapEnable(Interface.LinkUpDownTrapEnable.Enabled);
66 // Create the vhost augmentation
67 VppInterfaceAugmentationBuilder vppAugmentationBuilder = new VppInterfaceAugmentationBuilder()
68 .setVhostUser(new VhostUserBuilder().setRole(role).setSocket(socket).build());
70 if (getVrfId() != null) {
71 vppAugmentationBuilder.setRouting(new RoutingBuilder().setIpv4VrfId(getVrfId()).build());
74 if (!Strings.isNullOrEmpty(bridgeDomain)) {
75 vppAugmentationBuilder.setL2(new L2Builder()
76 .setInterconnection(new BridgeBasedBuilder().setBridgeDomain(bridgeDomain).build()).build());
79 interfaceBuilder.addAugmentation(VppInterfaceAugmentation.class, vppAugmentationBuilder.build());
80 addEnableProxyArpAugmentation(interfaceBuilder);
81 return interfaceBuilder;
85 public String toString() {
86 return "VhostUserCommand [socket=" + socket + ", role=" + role + ", bridgeDomain=" + bridgeDomain
87 + ", operation=" + operation + ", name=" + name + ", description=" + description + ", enabled="
91 public static class VhostUserCommandBuilder {
94 private General.Operations operation;
95 private String socket;
96 private VhostUserRole role = VhostUserRole.Server;
97 private boolean enabled = true;
98 private String description;
99 private String bridgeDomain;
100 private Boolean enableProxyArp;
103 public String getName() {
107 public VhostUserCommandBuilder setName(String name) {
112 public General.Operations getOperation() {
116 public VhostUserCommandBuilder setOperation(General.Operations operation) {
117 this.operation = operation;
121 public String getSocket() {
125 public VhostUserCommandBuilder setSocket(String socket) {
126 this.socket = socket;
130 VhostUserRole getRole() {
134 public VhostUserCommandBuilder setRole(VhostUserRole role) {
139 boolean isEnabled() {
143 VhostUserCommandBuilder setEnabled(boolean enabled) {
144 this.enabled = enabled;
148 public String getDescription() {
152 public VhostUserCommandBuilder setDescription(String description) {
153 this.description = description;
157 String getBridgeDomain() {
161 VhostUserCommandBuilder setBridgeDomain(String bridgeDomain) {
162 this.bridgeDomain = bridgeDomain;
166 public Boolean getEnableProxyArp() {
167 return enableProxyArp;
170 public void setEnableProxyArp(Boolean enableProxyArp) {
171 this.enableProxyArp = enableProxyArp;
174 public Long getVrfId() {
178 public void setVrfId(Long vrfId) {
183 * VhostUserCommand build method.
185 * @return VhostUserCommand
186 * @throws IllegalArgumentException if name, operation or socket is null.
188 public VhostUserCommand build() {
189 Preconditions.checkArgument(this.name != null);
190 Preconditions.checkArgument(this.operation != null);
191 if (operation == Operations.PUT) {
192 Preconditions.checkArgument(this.socket != null);
195 return new VhostUserCommand(this);