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.util.General;
14 import org.opendaylight.groupbasedpolicy.renderer.vpp.util.VppIidFactory;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 public abstract class AbstractInterfaceCommand<T extends AbstractInterfaceCommand<T>> implements ConfigCommand {
22 private static final Logger LOG = LoggerFactory.getLogger(AbstractInterfaceCommand.class);
24 protected General.Operations operation;
25 protected String name;
26 protected String description;
27 protected Boolean enabled;
29 protected enum linkUpDownTrap {
33 public General.Operations getOperation() {
37 public String getName() {
41 public String getDescription() {
45 public AbstractInterfaceCommand<T> setDescription(String description) {
46 this.description = description;
50 public Boolean getEnabled() {
54 public AbstractInterfaceCommand<T> setEnabled(Boolean enabled) {
55 this.enabled = enabled;
59 public void execute(ReadWriteTransaction rwTx) {
60 switch (getOperation()) {
62 LOG.debug("Executing Add operations for command: {}", this);
66 LOG.debug("Executing Delete operations for command: {}", this);
70 LOG.debug("Executing Update operations for command: {}", this);
74 LOG.error("Execution failed for command: {}", this);
79 private void put(ReadWriteTransaction rwTx) {
80 InterfaceBuilder interfaceBuilder = getInterfaceBuilder();
82 rwTx.put(LogicalDatastoreType.CONFIGURATION, VppIidFactory.getInterfaceIID(interfaceBuilder.getKey()),
83 interfaceBuilder.build(), true);
86 private void merge(ReadWriteTransaction rwTx) {
87 InterfaceBuilder interfaceBuilder = getInterfaceBuilder();
89 rwTx.merge(LogicalDatastoreType.CONFIGURATION, VppIidFactory.getInterfaceIID(interfaceBuilder.getKey()),
90 interfaceBuilder.build());
93 private void delete(ReadWriteTransaction readWriteTransaction) {
95 readWriteTransaction.delete(LogicalDatastoreType.CONFIGURATION,
96 VppIidFactory.getInterfaceIID(new InterfaceKey(name)));
97 } catch (IllegalStateException ex) {
98 LOG.debug("Interface is not present in DS {}", this, ex);