2 * Copyright (c) 2017 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;
13 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
14 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
15 import org.opendaylight.groupbasedpolicy.renderer.vpp.util.General;
16 import org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppIidFactory;
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.unnumbered.interfaces.rev170510.unnumbered.config.attributes.Unnumbered;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unnumbered.interfaces.rev170510.unnumbered.config.attributes.UnnumberedBuilder;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
22 public class UnnumberedInterfaceCommand extends AbstractConfigCommand {
23 private String useInterface;
24 private String interfaceName;
26 public UnnumberedInterfaceCommand(UnnumberedInterfaceCommandBuilder builder) {
27 this.operation = builder.getOperation();
28 this.useInterface = builder.getUseInterface();
29 this.interfaceName = builder.getInterfaceName();
32 public static UnnumberedInterfaceCommandBuilder builder() {
33 return new UnnumberedInterfaceCommandBuilder();
37 public InstanceIdentifier<Unnumbered> getIid() {
38 return VppIidFactory.getUnnumberedIid(new InterfaceKey(interfaceName));
41 public String getUseInterface() {
45 public String getInterfaceName() {
50 void put(ReadWriteTransaction rwTx) {
51 rwTx.put(LogicalDatastoreType.CONFIGURATION, getIid(), getUnnumberedBuilder().build(), true);
55 void merge(ReadWriteTransaction rwTx) {
56 rwTx.merge(LogicalDatastoreType.CONFIGURATION, getIid(), getUnnumberedBuilder().build(), true);
60 void delete(ReadWriteTransaction rwTx) {
61 rwTx.delete(LogicalDatastoreType.CONFIGURATION, getIid());
64 private UnnumberedBuilder getUnnumberedBuilder() {
65 return new UnnumberedBuilder().setUse(this.useInterface);
68 @Override public String toString() {
69 return "UnnumberedInterfaceCommand{" + "useInterface='" + useInterface + ", With='" + interfaceName + '}';
72 public static class UnnumberedInterfaceCommandBuilder {
73 private General.Operations operation;
74 private String useInterface;
75 private String interfaceName;
77 public General.Operations getOperation() {
81 public UnnumberedInterfaceCommandBuilder setOperation(General.Operations operation) {
82 this.operation = operation;
86 public String getUseInterface() {
90 public UnnumberedInterfaceCommandBuilder setUseInterface(String useInterface) {
91 this.useInterface = useInterface;
95 public String getInterfaceName() {
99 public UnnumberedInterfaceCommandBuilder setInterfaceName(String interfaceName) {
100 this.interfaceName = interfaceName;
105 * UnnumberedInterfaceCommand build method.
107 * @return UnnumberedInterfaceCommand
108 * @throws IllegalArgumentException if useInterface or interfaceName is null.
110 public UnnumberedInterfaceCommand build() {
111 Preconditions.checkNotNull(operation, "Operation must not be null!");
112 Preconditions.checkNotNull(useInterface, "Field useInterface must not be null!");
113 Preconditions.checkNotNull(interfaceName, "Field interfaceName must not be null!");
115 return new UnnumberedInterfaceCommand(this);