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 org.opendaylight.groupbasedpolicy.renderer.vpp.util.General;
12 import org.opendaylight.groupbasedpolicy.renderer.vpp.util.General.Operations;
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VhostUserRole;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppInterfaceAugmentation;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppInterfaceAugmentationBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.L2Builder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.VhostUserBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.base.attributes.interconnection.BridgeBasedBuilder;
23 import com.google.common.base.Preconditions;
24 import com.google.common.base.Strings;
26 public class VhostUserCommand extends AbstractInterfaceCommand<VhostUserCommand> {
28 private String socket;
29 private VhostUserRole role;
30 private String bridgeDomain;
32 private VhostUserCommand(VhostUserCommandBuilder builder) {
33 this.name = builder.getName();
34 this.operation = builder.getOperation();
35 this.socket = builder.getSocket();
36 this.role = builder.getRole();
37 this.enabled = builder.isEnabled();
38 this.description = builder.getDescription();
39 this.bridgeDomain = builder.getBridgeDomain();
43 public static VhostUserCommandBuilder builder() {
44 return new VhostUserCommandBuilder();
47 public String getSocket() {
51 public VhostUserRole getRole() {
55 public String getBridgeDomain() {
60 public InterfaceBuilder getInterfaceBuilder() {
61 InterfaceBuilder interfaceBuilder =
62 new InterfaceBuilder().setKey(new InterfaceKey(name))
64 .setDescription(description)
66 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VhostUser.class)
68 .setLinkUpDownTrapEnable(Interface.LinkUpDownTrapEnable.Enabled);
70 // Create the vhost augmentation
71 VppInterfaceAugmentationBuilder vppAugmentationBuilder = new VppInterfaceAugmentationBuilder()
72 .setVhostUser(new VhostUserBuilder().setRole(role).setSocket(socket).build());
73 if (!Strings.isNullOrEmpty(bridgeDomain)) {
74 vppAugmentationBuilder.setL2(new L2Builder()
75 .setInterconnection(new BridgeBasedBuilder().setBridgeDomain(bridgeDomain).build()).build());
78 interfaceBuilder.addAugmentation(VppInterfaceAugmentation.class, vppAugmentationBuilder.build());
79 return interfaceBuilder;
83 public String toString() {
84 return "VhostUserCommand [socket=" + socket + ", role=" + role + ", bridgeDomain=" + bridgeDomain
85 + ", operation=" + operation + ", name=" + name + ", description=" + description + ", enabled="
89 public static class VhostUserCommandBuilder {
92 private General.Operations operation;
93 private String socket;
94 private VhostUserRole role = VhostUserRole.Server;
95 private boolean enabled = true;
96 private String description;
97 private String bridgeDomain;
99 public String getName() {
103 public VhostUserCommandBuilder setName(String name) {
108 public General.Operations getOperation() {
112 public VhostUserCommandBuilder setOperation(General.Operations operation) {
113 this.operation = operation;
117 public String getSocket() {
121 public VhostUserCommandBuilder setSocket(String socket) {
122 this.socket = socket;
126 public VhostUserRole getRole() {
130 public VhostUserCommandBuilder setRole(VhostUserRole role) {
135 public boolean isEnabled() {
139 public VhostUserCommandBuilder setEnabled(boolean enabled) {
140 this.enabled = enabled;
144 public String getDescription() {
148 public VhostUserCommandBuilder setDescription(String description) {
149 this.description = description;
153 public String getBridgeDomain() {
157 public VhostUserCommandBuilder setBridgeDomain(String bridgeDomain) {
158 this.bridgeDomain = bridgeDomain;
163 * VhostUserCommand build method.
165 * @return VhostUserCommand
166 * @throws IllegalArgumentException if name, operation or socket is null.
168 public VhostUserCommand build() {
169 Preconditions.checkArgument(this.name != null);
170 Preconditions.checkArgument(this.operation != null);
171 if (operation == Operations.PUT) {
172 Preconditions.checkArgument(this.socket != null);
175 return new VhostUserCommand(this);