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.controller.md.sal.binding.api.ReadWriteTransaction;
12 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
13 import org.opendaylight.groupbasedpolicy.renderer.vpp.commands.interfaces.ConfigCommand;
14 import org.opendaylight.groupbasedpolicy.renderer.vpp.commands.interfaces.InterfaceCommand;
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.InterfaceBuilder;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.proxy.arp.rev170315.ProxyArpInterfaceAugmentation;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.proxy.arp.rev170315.ProxyArpInterfaceAugmentationBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.proxy.arp.rev170315.interfaces._interface.ProxyArpBuilder;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 public abstract class AbstractInterfaceCommand implements ConfigCommand, InterfaceCommand {
28 private static final Logger LOG = LoggerFactory.getLogger(AbstractInterfaceCommand.class);
30 protected General.Operations operation;
31 protected String name;
32 protected String description;
33 protected String bridgeDomain;
34 protected Boolean enabled;
35 protected Boolean enableProxyArp;
38 public General.Operations getOperation() {
42 public String getName() {
46 public Long getVrfId() {
50 public String getDescription() {
54 public AbstractInterfaceCommand setDescription(String description) {
55 this.description = description;
59 public String getBridgeDomain() {
63 public void execute(ReadWriteTransaction rwTx) {
64 switch (getOperation()) {
66 LOG.debug("Executing Add operations for command: {}", this);
70 LOG.debug("Executing Delete operations for command: {}", this);
74 LOG.debug("Executing Update operations for command: {}", this);
78 LOG.error("Execution failed for command: {}", this);
83 private void put(ReadWriteTransaction rwTx) {
84 InterfaceBuilder interfaceBuilder = getInterfaceBuilder();
86 rwTx.put(LogicalDatastoreType.CONFIGURATION, VppIidFactory.getInterfaceIID(interfaceBuilder.getKey()),
87 interfaceBuilder.build(), true);
90 private void merge(ReadWriteTransaction rwTx) {
91 InterfaceBuilder interfaceBuilder = getInterfaceBuilder();
93 rwTx.merge(LogicalDatastoreType.CONFIGURATION, VppIidFactory.getInterfaceIID(interfaceBuilder.getKey()),
94 interfaceBuilder.build());
97 private void delete(ReadWriteTransaction readWriteTransaction) {
99 readWriteTransaction.delete(LogicalDatastoreType.CONFIGURATION,
100 VppIidFactory.getInterfaceIID(new InterfaceKey(name)));
101 } catch (IllegalStateException ex) {
102 LOG.debug("Interface is not present in DS {}", this, ex);
106 @Override public InstanceIdentifier getIid() {
107 return VppIidFactory.getInterfaceIID(this.getInterfaceBuilder().getKey());
110 protected void addEnableProxyArpAugmentation(InterfaceBuilder interfaceBuilder) {
111 if (enableProxyArp != null) {
112 ProxyArpInterfaceAugmentationBuilder augmentationBuilder = new ProxyArpInterfaceAugmentationBuilder();
113 augmentationBuilder.setProxyArp((new ProxyArpBuilder()).build());
114 interfaceBuilder.addAugmentation(ProxyArpInterfaceAugmentation.class, augmentationBuilder.build());