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.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.Tap;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceAugmentation;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceAugmentationBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.L2Builder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.TapBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.base.attributes.interconnection.BridgeBasedBuilder;
26 public class TapPortCommand extends AbstractInterfaceCommand<TapPortCommand> {
28 private String tapName;
29 private PhysAddress physAddress;
30 private String bridgeDomain;
31 private Long deviceInstance;
33 private TapPortCommand(TapPortCommandBuilder builder) {
34 this.name = builder.getInterfaceName();
35 this.tapName = builder.getTapName();
36 this.operation = builder.getOperation();
37 this.physAddress = builder.getPhysAddress();
38 this.enabled = builder.isEnabled();
39 this.description = builder.getDescription();
40 this.bridgeDomain = builder.getBridgeDomain();
41 this.deviceInstance = builder.getDeviceInstance();
44 public static TapPortCommandBuilder builder() {
45 return new TapPortCommandBuilder();
48 public PhysAddress getPhysAddress() {
52 public String getBridgeDomain() {
56 public Long getDeviceInstance() {
57 return deviceInstance;
60 public String getTapName() {
65 public InterfaceBuilder getInterfaceBuilder() {
66 InterfaceBuilder interfaceBuilder = new InterfaceBuilder().setKey(new InterfaceKey(name))
68 .setDescription(description)
71 .setLinkUpDownTrapEnable(Interface.LinkUpDownTrapEnable.Enabled);
73 // Create the Tap augmentation
74 VppInterfaceAugmentationBuilder vppAugmentationBuilder =
75 new VppInterfaceAugmentationBuilder().setTap(new TapBuilder().setMac(this.physAddress)
76 .setTapName(this.tapName)
77 .setMac(this.physAddress)
78 .setDeviceInstance(this.deviceInstance)
81 if (!Strings.isNullOrEmpty(bridgeDomain)) {
82 vppAugmentationBuilder.setL2(new L2Builder()
83 .setInterconnection(new BridgeBasedBuilder().setBridgeDomain(bridgeDomain).build()).build());
86 interfaceBuilder.addAugmentation(VppInterfaceAugmentation.class, vppAugmentationBuilder.build());
87 return interfaceBuilder;
91 public String toString() {
92 return "TapPortUserCommand [physAddress=" + physAddress + ", bridgeDomain=" + bridgeDomain + ", operations="
93 + operation + ", name=" + name + ", tapName=" + tapName + ", description=" + description + ", enabled="
97 public static class TapPortCommandBuilder {
99 private String interfaceName;
100 private String tapName;
101 private Operations operation;
102 private PhysAddress physAddress;
103 private String bridgeDomain;
104 private String description;
105 private Long deviceInstance = null;
106 private boolean enabled = true;
108 public String getInterfaceName() {
109 return interfaceName;
112 public TapPortCommandBuilder setInterfaceName(String interfaceName) {
113 this.interfaceName = interfaceName;
117 public String getTapName() {
121 public TapPortCommandBuilder setTapName(String tapName) {
122 this.tapName = tapName;
126 public General.Operations getOperation() {
130 public TapPortCommandBuilder setOperation(Operations operation) {
131 this.operation = operation;
135 public PhysAddress getPhysAddress() {
139 public TapPortCommandBuilder setPhysAddress(PhysAddress physAddress) {
140 this.physAddress = physAddress;
144 public String getBridgeDomain() {
148 public TapPortCommandBuilder setBridgeDomain(String bridgeDomain) {
149 this.bridgeDomain = bridgeDomain;
153 public String getDescription() {
157 public TapPortCommandBuilder setDescription(String description) {
158 this.description = description;
162 public Long getDeviceInstance() {
163 return deviceInstance;
166 public TapPortCommandBuilder setDeviceInstance(Long deviceInstance) {
167 this.deviceInstance = deviceInstance;
171 public boolean isEnabled() {
175 public TapPortCommandBuilder setEnabled(boolean enabled) {
176 this.enabled = enabled;
181 * TapPortCommand build method.
183 * @return TapPortCommand
184 * @throws IllegalArgumentException if interfaceName, tapName or operation is null.
186 public TapPortCommand build() {
187 Preconditions.checkArgument(this.interfaceName != null);
188 Preconditions.checkArgument(this.tapName != null);
189 Preconditions.checkArgument(this.operation != null);
191 return new TapPortCommand(this);