<artifactId>vbd-api</artifactId>
<version>1.1.0-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.honeycomb.vbd</groupId>
+ <artifactId>vbd-impl</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ </dependency>
<dependency>
<groupId>org.opendaylight.mdsal.model</groupId>
<artifactId>opendaylight-l2-types</artifactId>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
- <extensions>true</extensions>
<configuration>
<instructions>
<Export-Package>
org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.*,
org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_adapter.rev161201.*
</Export-Package>
+ <Import-Package>
+ *
+ </Import-Package>
</instructions>
</configuration>
</plugin>
public ListenableFuture<Void> createInterfaceOnVpp(final ConfigCommand createIfaceWithoutBdCommand,
final DataBroker vppDataBroker) {
- final boolean transactionState = GbpNetconfTransaction.write(vppDataBroker, createIfaceWithoutBdCommand,
+ final boolean transactionState = GbpNetconfTransaction.netconfSyncedWrite(vppDataBroker, createIfaceWithoutBdCommand,
GbpNetconfTransaction.RETRY_COUNT);
if (transactionState) {
LOG.trace("Creating Interface on VPP: {}", createIfaceWithoutBdCommand);
final DataBroker vppDataBroker,
final VppEndpoint vppEndpoint,
final InstanceIdentifier<?> vppNodeIid) {
- final boolean transactionState = GbpNetconfTransaction.write(vppDataBroker, createIfaceWithoutBdCommand,
+ final boolean transactionState = GbpNetconfTransaction.netconfSyncedWrite(vppDataBroker, createIfaceWithoutBdCommand,
GbpNetconfTransaction.RETRY_COUNT);
if (transactionState) {
LOG.debug("Create interface on VPP command was successful. VPP: {} Command: {}", vppNodeIid,
private ListenableFuture<Void> deleteIfaceOnVpp(ConfigCommand deleteIfaceWithoutBdCommand,
DataBroker vppDataBroker, VppEndpoint vppEndpoint, InstanceIdentifier<?> vppNodeIid) {
- final boolean transactionState = GbpNetconfTransaction.deleteIfExists(vppDataBroker, deleteIfaceWithoutBdCommand,
- GbpNetconfTransaction.RETRY_COUNT);
+ final boolean transactionState = GbpNetconfTransaction.netconfSyncedDelete(vppDataBroker,
+ deleteIfaceWithoutBdCommand, GbpNetconfTransaction.RETRY_COUNT);
if (transactionState) {
LOG.debug("Delete interface on VPP command was successful: VPP: {} Command: {}", vppNodeIid,
deleteIfaceWithoutBdCommand);
.setBridgedVirtualInterface(enableBvi)
.build()).build();
LOG.debug("Adding bridge domain {} to interface {}", bridgeDomainName, interfacePath);
- final boolean transactionState = GbpNetconfTransaction.write(mountpoint, l2Iid, l2,
+ final boolean transactionState = GbpNetconfTransaction.netconfSyncedWrite(mountpoint, l2Iid, l2,
GbpNetconfTransaction.RETRY_COUNT);
if (transactionState) {
LOG.debug("Adding bridge domain {} to interface {} successful", bridgeDomainName, interfacePath);
.setBridgeDomain(bridgeDomainName)
.setBridgedVirtualInterface(enableBvi)
.build()).build();
- final boolean transactionState = GbpNetconfTransaction.write(mountPoint, VppIidFactory.getL2ForInterfaceIid(ifaceKey),
- l2, GbpNetconfTransaction.RETRY_COUNT);
+ final boolean transactionState = GbpNetconfTransaction.netconfSyncedWrite(mountPoint,
+ VppIidFactory.getL2ForInterfaceIid(ifaceKey), l2, GbpNetconfTransaction.RETRY_COUNT);
if (transactionState) {
LOG.debug("Adding bridge domain {} to interface {}", bridgeDomainName, VppIidFactory.getInterfaceIID(ifaceKey));
return Futures.immediateFuture(null);
LOG.warn("Interface already not in bridge domain {} ", ifaceKey);
return Futures.immediateFuture(null);
}
- final boolean transactionState = GbpNetconfTransaction.deleteIfExists(mountPoint,
+ final boolean transactionState = GbpNetconfTransaction.netconfSyncedDelete(mountPoint,
VppIidFactory.getL2ForInterfaceIid(ifaceKey), GbpNetconfTransaction.RETRY_COUNT);
if (transactionState) {
LOG.debug("Removing bridge domain from interface {}", VppIidFactory.getInterfaceIID(ifaceKey));
interfaceIid.builder().augmentation(VppInterfaceAugmentation.class).child(L2.class).build();
LOG.debug("Deleting bridge domain from interface {}", interfacePath);
final boolean transactionState =
- GbpNetconfTransaction.deleteIfExists(mountpoint, l2Iid, GbpNetconfTransaction.RETRY_COUNT);
+ GbpNetconfTransaction.netconfSyncedDelete(mountpoint, l2Iid, GbpNetconfTransaction.RETRY_COUNT);
if (transactionState) {
AccessListWrapper.removeAclsForInterface(mountpoint, interfaceIid.firstKeyOf(Interface.class));
AccessListWrapper.removeAclRefFromIface(mountpoint, interfaceIid.firstKeyOf(Interface.class));
public void writeAcl(@Nonnull DataBroker mountPoint, @Nonnull InterfaceKey ifaceKey) {
Acl builtAcl = this.buildVppAcl(ifaceKey);
LOG.info("Writing access-list {}", builtAcl.getAclName());
- boolean write = GbpNetconfTransaction.write(mountPoint, VppIidFactory.getVppAcl(resolveAclName(ifaceKey)),
- builtAcl, GbpNetconfTransaction.RETRY_COUNT);
+ boolean write = GbpNetconfTransaction.netconfSyncedWrite(mountPoint,
+ VppIidFactory.getVppAcl(resolveAclName(ifaceKey)), builtAcl, GbpNetconfTransaction.RETRY_COUNT);
if (!write) {
LOG.error("Failed to write rule {}", builtAcl);
}
public static void removeAclsForInterface(@Nonnull DataBroker mountPoint, @Nonnull InterfaceKey ifaceKey) {
LOG.debug("Removing access-list {}", ifaceKey);
for (ACE_DIRECTION dir : new ACE_DIRECTION[] {ACE_DIRECTION.INGRESS, ACE_DIRECTION.EGRESS}) {
- GbpNetconfTransaction.deleteIfExists(mountPoint, VppIidFactory.getVppAcl(ifaceKey.getName() + dir),
- GbpNetconfTransaction.RETRY_COUNT);
+ GbpNetconfTransaction.netconfSyncedDelete(mountPoint,
+ VppIidFactory.getVppAcl(ifaceKey.getName() + dir), GbpNetconfTransaction.RETRY_COUNT);
}
}
public static void removeAclRefFromIface(@Nonnull DataBroker mountPoint, @Nonnull InterfaceKey ifaceKey) {
LOG.debug("Removing access-lists from interface {}", ifaceKey.getName());
- GbpNetconfTransaction.deleteIfExists(mountPoint, VppIidFactory.getInterfaceIetfAcl(ifaceKey),
+ GbpNetconfTransaction.netconfSyncedDelete(mountPoint, VppIidFactory.getInterfaceIetfAcl(ifaceKey),
GbpNetconfTransaction.RETRY_COUNT);
}
}
.setType(VppAcl.class)
.build();
Egress egressAcl = new EgressBuilder().setVppAcls(ImmutableList.<VppAcls>of(vppAcl)).build();
- GbpNetconfTransaction.write(mountPoint, egressRefIid, egressAcl, GbpNetconfTransaction.RETRY_COUNT);
+ GbpNetconfTransaction.netconfSyncedWrite(mountPoint, egressRefIid, egressAcl,
+ GbpNetconfTransaction.RETRY_COUNT);
}
private InstanceIdentifier<Egress> outboundIfaceAclRefIid(InstanceIdentifier<Interface> ifaceIid) {
.setType(VppAcl.class)
.build();
Ingress egressAcl = new IngressBuilder().setVppAcls(ImmutableList.<VppAcls>of(vppAcl)).build();
- GbpNetconfTransaction.write(mountPoint, ingressRefIid, egressAcl, GbpNetconfTransaction.RETRY_COUNT);
+ GbpNetconfTransaction.netconfSyncedWrite(mountPoint, ingressRefIid, egressAcl,
+ GbpNetconfTransaction.RETRY_COUNT);
}
private InstanceIdentifier<Ingress> outboundIfaceAclRefIid(InstanceIdentifier<Interface> ifaceIid) {
package org.opendaylight.groupbasedpolicy.renderer.vpp.util;
+import javax.annotation.Nonnull;
+
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.groupbasedpolicy.renderer.vpp.commands.ConfigCommand;
+import org.opendaylight.vbd.impl.transaction.VbdNetconfTransaction;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
public static final byte RETRY_COUNT = 3;
private static final Logger LOG = LoggerFactory.getLogger(GbpNetconfTransaction.class);
+ /***
+ * Netconf wrapper for write and delete operation on a Netconf Device
+ * @param mountpoint netconf device
+ * @param iid path for Data to be written to
+ * @param data data to be written
+ * @param retryCounter retry counter, will repeat the operation for specified amount of times if transaction fails
+ * @param <T> data type
+ * @return true if transaction is successful, false otherwise
+ */
+ public static <T extends DataObject> boolean netconfSyncedWrite(@Nonnull final DataBroker mountpoint,
+ @Nonnull final InstanceIdentifier<T> iid, @Nonnull final T data, byte retryCounter) {
+ VbdNetconfTransaction.REENTRANT_LOCK.lock();
+ boolean result = write(mountpoint, iid, data, retryCounter);
+ VbdNetconfTransaction.REENTRANT_LOCK.unlock();
+ return result;
+ }
+
+ /***
+ * Netconf wrapper method for synced requests for write operation on a Netconf Device
+ * @param mountpoint netconf device
+ * @param command config command that needs to be executed
+ * @param retryCounter retry counter, will repeat the operation for specified amount of times if transaction fails
+ * @return true if transaction is successful, false otherwise
+ */
+ public static boolean netconfSyncedWrite(@Nonnull final DataBroker mountpoint, @Nonnull final ConfigCommand command,
+ byte retryCounter) {
+ VbdNetconfTransaction.REENTRANT_LOCK.lock();
+ boolean result = write(mountpoint, command, retryCounter);
+ VbdNetconfTransaction.REENTRANT_LOCK.unlock();
+ return result;
+ }
+
+ /***
+ * Netconf wrapper method for synced requests for delete operation on a Netconf Device
+ * @param mountpoint netconf device
+ * @param iid path for Data to be written to
+ * @param retryCounter retry counter, will repeat the operation for specified amount of times if transaction fails
+ * @param <T> data type
+ * @return true if transaction is successful, false otherwise
+ */
+ public static <T extends DataObject> boolean netconfSyncedDelete(@Nonnull final DataBroker mountpoint,
+ @Nonnull final InstanceIdentifier<T> iid, byte retryCounter) {
+ VbdNetconfTransaction.REENTRANT_LOCK.lock();
+ boolean result = deleteIfExists(mountpoint, iid, retryCounter);
+ VbdNetconfTransaction.REENTRANT_LOCK.unlock();
+ return result;
+ }
+
+ /***
+ * Netconf wrapper method for synced requests for delete operation on a Netconf Device
+ * @param mountpoint netconf device
+ * @param command config command that needs to be executed
+ * @param retryCounter retry counter, will repeat the operation for specified amount of times if transaction fails
+ * @return true if transaction is successful, false otherwise
+ */
+ public static boolean netconfSyncedDelete(@Nonnull final DataBroker mountpoint,
+ @Nonnull final ConfigCommand command, byte retryCounter) {
+ VbdNetconfTransaction.REENTRANT_LOCK.lock();
+ boolean result = deleteIfExists(mountpoint, command, retryCounter);
+ VbdNetconfTransaction.REENTRANT_LOCK.unlock();
+ return result;
+ }
+
+
/**
* Use {@link ConfigCommand} to put data into netconf transaction and submit. Transaction is restarted if failed
*
* @param retryCounter number of attempts
* @return true if transaction is successful, false otherwise
*/
- public static synchronized boolean write(final DataBroker mountpoint, final ConfigCommand command,
- byte retryCounter) {
+ private static boolean write(final DataBroker mountpoint, final ConfigCommand command, byte retryCounter) {
LOG.trace("Netconf WRITE transaction started. RetryCounter: {}", retryCounter);
Preconditions.checkNotNull(mountpoint);
final ReadWriteTransaction rwTx = mountpoint.newReadWriteTransaction();
* @param <T> generic data type. Has to be child of {@link DataObject}
* @return true if transaction is successful, false otherwise
*/
- public static synchronized <T extends DataObject> boolean write(final DataBroker mountpoint,
+ private static <T extends DataObject> boolean write(final DataBroker mountpoint,
final InstanceIdentifier<T> iid,
final T data,
byte retryCounter) {
* @param retryCounter number of attempts
* @return true if transaction is successful, false otherwise
*/
- public static synchronized boolean deleteIfExists(final DataBroker mountpoint, final ConfigCommand command,
+ private static boolean deleteIfExists(final DataBroker mountpoint, final ConfigCommand command,
byte retryCounter) {
Preconditions.checkNotNull(mountpoint);
InstanceIdentifier<Interface> iid = VppIidFactory.getInterfaceIID(command.getInterfaceBuilder().getKey());
* @param <T> generic data type. Has to be child of {@link DataObject}
* @return true if transaction is successful, false otherwise
*/
- public static synchronized <T extends DataObject> boolean deleteIfExists(final DataBroker mountpoint,
+ private static <T extends DataObject> boolean deleteIfExists(final DataBroker mountpoint,
final InstanceIdentifier<T> iid,
byte retryCounter) {
LOG.trace("Netconf DELETE transaction started. Data will be read at first. RetryCounter: {}", retryCounter);
}
}
}
-}
\ No newline at end of file
+}
public void writeConfigCommandReattemptTest() {
doThrow(new IllegalStateException()).when(command).execute(rwTx);
- final boolean result = GbpNetconfTransaction.write(dataBroker, command, (byte)5);
+ final boolean result = GbpNetconfTransaction.netconfSyncedWrite(dataBroker, command, (byte) 5);
verify(dataBroker, times(6)).newReadWriteTransaction();
assertFalse(result);
}
doNothing().when(command).execute(rwTx);
when(future.get()).thenReturn(null);
- final boolean result = GbpNetconfTransaction.write(dataBroker, command, (byte)5);
+ final boolean result = GbpNetconfTransaction.netconfSyncedWrite(dataBroker, command, (byte)5);
verify(dataBroker, times(1)).newReadWriteTransaction();
assertTrue(result);
}
public void writeDataReattemptTest() {
doThrow(new IllegalStateException()).when(rwTx).put(LogicalDatastoreType.CONFIGURATION, nodeIid, node, true);
- final boolean result = GbpNetconfTransaction.write(dataBroker, nodeIid, node, (byte)5);
+ final boolean result = GbpNetconfTransaction.netconfSyncedWrite(dataBroker, nodeIid, node, (byte) 5);
verify(dataBroker, times(6)).newReadWriteTransaction();
assertFalse(result);
}
doNothing().when(rwTx).put(LogicalDatastoreType.CONFIGURATION, nodeIid, node, true);
when(future.get()).thenReturn(null);
- final boolean result = GbpNetconfTransaction.write(dataBroker, nodeIid, node, (byte)5);
+ final boolean result = GbpNetconfTransaction.netconfSyncedWrite(dataBroker, nodeIid, node, (byte) 5);
verify(dataBroker, times(1)).newReadWriteTransaction();
assertTrue(result);
}
when(futureInterface.get()).thenReturn(Optional.absent());
doThrow(new IllegalStateException()).when(command).execute(rwTx);
- final boolean result = GbpNetconfTransaction.deleteIfExists(dataBroker, command, (byte)5);
+ final boolean result = GbpNetconfTransaction.netconfSyncedDelete(dataBroker, command, (byte)5);
verify(dataBroker, times(1)).newReadOnlyTransaction();
assertTrue(result);
}
.setKey(new InterfaceKey(INTERFACE_KEY)).build()));
doThrow(new IllegalStateException()).when(command).execute(rwTx);
- final boolean result = GbpNetconfTransaction.deleteIfExists(dataBroker, command, (byte)5);
+ final boolean result = GbpNetconfTransaction.netconfSyncedDelete(dataBroker, command, (byte)5);
verify(dataBroker, times(6)).newReadWriteTransaction();
assertFalse(result);
}
doNothing().when(command).execute(rwTx);
when(future.get()).thenReturn(null);
- final boolean result = GbpNetconfTransaction.deleteIfExists(dataBroker, command, (byte)5);
+ final boolean result = GbpNetconfTransaction.netconfSyncedDelete(dataBroker, command, (byte)5);
verify(dataBroker, times(1)).newReadWriteTransaction();
assertTrue(result);
}
when(futureNode.get()).thenReturn(Optional.absent());
doThrow(new IllegalStateException()).when(command).execute(rwTx);
- final boolean result = GbpNetconfTransaction.deleteIfExists(dataBroker, nodeIid, (byte)5);
+ final boolean result = GbpNetconfTransaction.netconfSyncedDelete(dataBroker, nodeIid, (byte)5);
verify(dataBroker, times(1)).newReadOnlyTransaction();
assertTrue(result);
}
.setKey(new NodeKey(new NodeId(NODE_ID))).build()));
doThrow(new IllegalStateException()).when(rwTx).delete(LogicalDatastoreType.CONFIGURATION, nodeIid);
- final boolean result = GbpNetconfTransaction.deleteIfExists(dataBroker, nodeIid, (byte)5);
+ final boolean result = GbpNetconfTransaction.netconfSyncedDelete(dataBroker, nodeIid, (byte)5);
verify(dataBroker, times(6)).newReadWriteTransaction();
assertFalse(result);
}
doNothing().when(rwTx).delete(LogicalDatastoreType.CONFIGURATION, nodeIid);
when(future.get()).thenReturn(null);
- final boolean result = GbpNetconfTransaction.deleteIfExists(dataBroker, nodeIid, (byte)5);
+ final boolean result = GbpNetconfTransaction.netconfSyncedDelete(dataBroker, nodeIid, (byte)5);
verify(dataBroker, times(1)).newReadWriteTransaction();
assertTrue(result);
}
-}
\ No newline at end of file
+}