<groupId>org.apache.aries.blueprint</groupId>
<artifactId>blueprint-maven-plugin</artifactId>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <configuration>
+ <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+ </configuration>
+ </plugin>
</plugins>
</build>
</project>
/*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
*/
package org.opendaylight.genius.mdsalutil.internal;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.genius.utils.batching.ActionableResource;
import org.opendaylight.genius.utils.batching.ActionableResourceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.LinkedBlockingQueue;
-
public class FlowBatchingUtils {
- private static final Logger LOG = LoggerFactory.getLogger((Class)FlowBatchingUtils.class);
+ private static final Logger LOG = LoggerFactory.getLogger(FlowBatchingUtils.class);
public static final int BATCH_SIZE = 1000;
public static final int PERIODICITY = 500;
public static Integer batchSize;
batchInterval = Integer.getInteger("batch.wait.time");
}
ResourceBatchingManager resBatchingManager = ResourceBatchingManager.getInstance();
- resBatchingManager.registerBatchableResource("MDSALUTIL-INVENTORY-CONFIG", inventoryConfigShardBufferQ, resourceHandler);
+ resBatchingManager.registerBatchableResource("MDSALUTIL-INVENTORY-CONFIG", inventoryConfigShardBufferQ,
+ resourceHandler);
}
static <T extends DataObject> void update(InstanceIdentifier<T> path, T data) {
/*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
import org.slf4j.LoggerFactory;
@Singleton
-public class MDSALManager extends AbstractLifecycle implements IMdsalApiManager{
+@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
+public class MDSALManager extends AbstractLifecycle implements IMdsalApiManager {
private static final long FIXED_DELAY_IN_MILLISECONDS = 5000;
- private static final Logger s_logger = LoggerFactory.getLogger(MDSALManager.class);
+ private static final Logger LOG = LoggerFactory.getLogger(MDSALManager.class);
- private final DataBroker m_dataBroker;
+ private final DataBroker dataBroker;
- private final PacketProcessingService m_packetProcessingService;
+ private final PacketProcessingService packetProcessingService;
private final ConcurrentMap<FlowInfoKey, Runnable> flowMap = new ConcurrentHashMap<>();
private final ConcurrentMap<GroupInfoKey, Runnable> groupMap = new ConcurrentHashMap<>();
private final ExecutorService executorService = Executors.newSingleThreadExecutor();
/**
- * Writes the flows and Groups to the MD SAL DataStore
- * which will be sent to the openflowplugin for installing flows/groups on the switch.
- * Other modules of VPN service that wants to install flows / groups on the switch
+ * Writes the flows and Groups to the MD SAL DataStore which will be sent to
+ * the openflowplugin for installing flows/groups on the switch. Other
+ * modules of VPN service that wants to install flows / groups on the switch
* uses this utility
*
- * @param db - dataBroker reference
- * @param pktProcService- PacketProcessingService for sending the packet outs
+ * @param db
+ * dataBroker reference
+ * @param pktProcService
+ * PacketProcessingService for sending the packet outs
*/
@Inject
public MDSALManager(DataBroker db, PacketProcessingService pktProcService) {
- m_dataBroker = db;
- m_packetProcessingService = pktProcService;
- s_logger.info( "MDSAL Manager Initialized ") ;
+ this.dataBroker = db;
+ this.packetProcessingService = pktProcService;
+ LOG.info("MDSAL Manager Initialized ");
}
@Override
protected void start() throws Exception {
- s_logger.info("{} start", getClass().getSimpleName());
- registerListener(m_dataBroker);
+ LOG.info("{} start", getClass().getSimpleName());
+ registerListener(dataBroker);
}
@Override
protected void stop() throws Exception {
- s_logger.info("{} stop", getClass().getSimpleName());
+ LOG.info("{} stop", getClass().getSimpleName());
}
private void registerListener(DataBroker db) {
- try {
- FlowListener flowListener = new FlowListener();
- GroupListener groupListener = new GroupListener();
- FlowBatchingUtils.registerWithBatchManager(new MdSalUtilBatchHandler(), db);
- flowListener.registerListener(LogicalDatastoreType.OPERATIONAL, db);
- groupListener.registerListener(LogicalDatastoreType.OPERATIONAL, db);
- } catch (final Exception e) {
- s_logger.error("GroupEventHandler: DataChange listener registration fail!", e);
- throw new IllegalStateException("GroupEventHandler: registration Listener failed.", e);
- }
+ FlowListener flowListener = new FlowListener();
+ GroupListener groupListener = new GroupListener();
+ FlowBatchingUtils.registerWithBatchManager(new MdSalUtilBatchHandler(), db);
+ flowListener.registerListener(LogicalDatastoreType.OPERATIONAL, db);
+ groupListener.registerListener(LogicalDatastoreType.OPERATIONAL, db);
}
private InstanceIdentifier<Group> getWildCardGroupPath() {
- return InstanceIdentifier.create(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class).child(Group.class);
+ return InstanceIdentifier.create(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class)
+ .child(Group.class);
}
private InstanceIdentifier<Flow> getWildCardFlowPath() {
- return InstanceIdentifier.create(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class).child(Table.class).child(Flow.class);
+ return InstanceIdentifier.create(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class)
+ .child(Table.class).child(Flow.class);
}
public CheckedFuture<Void, TransactionCommitFailedException> installFlowInternal(FlowEntity flowEntity) {
- WriteTransaction tx = m_dataBroker.newWriteOnlyTransaction();
- s_logger.trace("InstallFlow for flowEntity {} ", flowEntity);
+ WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
+ LOG.trace("InstallFlow for flowEntity {} ", flowEntity);
- writeFlowEntityInternal(flowEntity, tx);
+ writeFlowEntityInternal(flowEntity, tx);
- CheckedFuture<Void,TransactionCommitFailedException> submitFuture = tx.submit();
+ CheckedFuture<Void, TransactionCommitFailedException> submitFuture = tx.submit();
- Futures.addCallback(submitFuture, new FutureCallback<Void>() {
+ Futures.addCallback(submitFuture, new FutureCallback<Void>() {
- @Override
- public void onSuccess(final Void result) {
- // Commited successfully
- s_logger.debug( "Install Flow -- Committedsuccessfully ") ;
- }
+ @Override
+ public void onSuccess(final Void result) {
+ // Committed successfully
+ LOG.debug("Install Flow -- Committedsuccessfully ");
+ }
- @Override
- public void onFailure(final Throwable t) {
- // Transaction failed
-
- if(t instanceof OptimisticLockFailedException) {
- // Failed because of concurrent transaction modifying same data
- s_logger.error( "Install Flow -- Failed because of concurrent transaction modifying same data ") ;
- } else {
- // Some other type of TransactionCommitFailedException
- s_logger.error( "Install Flow -- Some other type of TransactionCommitFailedException " + t) ;
- }
+ @Override
+ public void onFailure(final Throwable throwable) {
+ // Transaction failed
+
+ if (throwable instanceof OptimisticLockFailedException) {
+ // Failed because of concurrent transaction modifying same
+ // data
+ LOG.error("Install Flow -- Failed because of concurrent transaction modifying same data");
+ } else {
+ // Some other type of TransactionCommitFailedException
+ LOG.error("Install Flow -- Some other type of TransactionCommitFailedException", throwable);
}
- });
+ }
+ });
- return submitFuture;
+ return submitFuture;
+ }
+
+ public CheckedFuture<Void, TransactionCommitFailedException> installFlowInternal(BigInteger dpId, Flow flow) {
+ WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
+ writeFlowInternal(dpId, flow, tx);
+ return tx.submit();
}
public void writeFlowEntityInternal(FlowEntity flowEntity, WriteTransaction tx) {
flowEntity.setCookie(new BigInteger("0110000", 16));
}
- FlowKey flowKey = new FlowKey( new FlowId(flowEntity.getFlowId()) );
+ FlowKey flowKey = new FlowKey(new FlowId(flowEntity.getFlowId()));
FlowBuilder flowbld = flowEntity.getFlowBuilder();
Node nodeDpn = buildDpnNode(flowEntity.getDpnId());
InstanceIdentifier<Flow> flowInstanceId = InstanceIdentifier.builder(Nodes.class)
.child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class)
- .child(Table.class, new TableKey(flowEntity.getTableId())).child(Flow.class,flowKey).build();
-
- tx.put(LogicalDatastoreType.CONFIGURATION, flowInstanceId, flowbld.build(),true );
- }
+ .child(Table.class, new TableKey(flowEntity.getTableId())).child(Flow.class, flowKey).build();
- public CheckedFuture<Void,TransactionCommitFailedException> installFlowInternal(BigInteger dpId, Flow flow) {
- WriteTransaction tx = m_dataBroker.newWriteOnlyTransaction();
- writeFlowInternal(dpId, flow, tx);
- return tx.submit();
+ tx.put(LogicalDatastoreType.CONFIGURATION, flowInstanceId, flowbld.build(), true);
}
public void writeFlowInternal(BigInteger dpId, Flow flow, WriteTransaction tx) {
- FlowKey flowKey = new FlowKey( new FlowId(flow.getId()) );
+ FlowKey flowKey = new FlowKey(new FlowId(flow.getId()));
Node nodeDpn = buildDpnNode(dpId);
InstanceIdentifier<Flow> flowInstanceId = InstanceIdentifier.builder(Nodes.class)
.child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class)
- .child(Table.class, new TableKey(flow.getTableId())).child(Flow.class,flowKey).build();
+ .child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flowKey).build();
tx.put(LogicalDatastoreType.CONFIGURATION, flowInstanceId, flow, true);
}
public void batchedAddFlowInternal(BigInteger dpId, Flow flow) {
- FlowKey flowKey = new FlowKey( new FlowId(flow.getId()) );
+ FlowKey flowKey = new FlowKey(new FlowId(flow.getId()));
Node nodeDpn = buildDpnNode(dpId);
InstanceIdentifier<Flow> flowInstanceId = InstanceIdentifier.builder(Nodes.class)
.child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class)
- .child(Table.class, new TableKey(flow.getTableId())).child(Flow.class,flowKey).build();
+ .child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flowKey).build();
FlowBatchingUtils.write(flowInstanceId, flow);
}
public void batchedRemoveFlowInternal(BigInteger dpId, Flow flow) {
- FlowKey flowKey = new FlowKey( new FlowId(flow.getId()) );
+ FlowKey flowKey = new FlowKey(new FlowId(flow.getId()));
Node nodeDpn = buildDpnNode(dpId);
InstanceIdentifier<Flow> flowInstanceId = InstanceIdentifier.builder(Nodes.class)
.child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class)
- .child(Table.class, new TableKey(flow.getTableId())).child(Flow.class,flowKey).build();
+ .child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flowKey).build();
FlowBatchingUtils.delete(flowInstanceId);
}
public CheckedFuture<Void, TransactionCommitFailedException> installGroupInternal(GroupEntity groupEntity) {
- WriteTransaction tx = m_dataBroker.newWriteOnlyTransaction();
- writeGroupEntityInternal(groupEntity, tx);
+ WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
+ writeGroupEntityInternal(groupEntity, tx);
- CheckedFuture<Void,TransactionCommitFailedException> submitFuture = tx.submit();
+ CheckedFuture<Void, TransactionCommitFailedException> submitFuture = tx.submit();
- Futures.addCallback(submitFuture, new FutureCallback<Void>() {
- @Override
- public void onSuccess(final Void result) {
- // Commited successfully
- s_logger.debug( "Install Group -- Committedsuccessfully ") ;
- }
+ Futures.addCallback(submitFuture, new FutureCallback<Void>() {
+ @Override
+ public void onSuccess(final Void result) {
+ // Committed successfully
+ LOG.debug("Install Group -- Committedsuccessfully ");
+ }
- @Override
- public void onFailure(final Throwable t) {
- // Transaction failed
-
- if(t instanceof OptimisticLockFailedException) {
- // Failed because of concurrent transaction modifying same data
- s_logger.error( "Install Group -- Failed because of concurrent transaction modifying same data ") ;
- } else {
- // Some other type of TransactionCommitFailedException
- s_logger.error( "Install Group -- Some other type of TransactionCommitFailedException " + t) ;
- }
+ @Override
+ public void onFailure(final Throwable throwable) {
+ // Transaction failed
+
+ if (throwable instanceof OptimisticLockFailedException) {
+ // Failed because of concurrent transaction modifying same
+ // data
+ LOG.error("Install Group -- Failed because of concurrent transaction modifying same data");
+ } else {
+ // Some other type of TransactionCommitFailedException
+ LOG.error("Install Group -- Some other type of TransactionCommitFailedException", throwable);
}
- });
+ }
+ });
- return submitFuture;
+ return submitFuture;
}
public void writeGroupEntityInternal(GroupEntity groupEntity, WriteTransaction tx) {
}
public CheckedFuture<Void, TransactionCommitFailedException> removeFlowInternal(FlowEntity flowEntity) {
- WriteTransaction tx = m_dataBroker.newWriteOnlyTransaction();
- deleteFlowEntityInternal(flowEntity, tx);
+ WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
+ deleteFlowEntityInternal(flowEntity, tx);
- CheckedFuture<Void,TransactionCommitFailedException> submitFuture = tx.submit();
+ CheckedFuture<Void, TransactionCommitFailedException> submitFuture = tx.submit();
- Futures.addCallback(submitFuture, new FutureCallback<Void>() {
- @Override
- public void onSuccess(final Void result) {
- // Commited successfully
- s_logger.debug( "Delete Flow -- Committedsuccessfully ") ;
- }
+ Futures.addCallback(submitFuture, new FutureCallback<Void>() {
+ @Override
+ public void onSuccess(final Void result) {
+ // Committed successfully
+ LOG.debug("Delete Flow -- Committedsuccessfully ");
+ }
- @Override
- public void onFailure(final Throwable t) {
- // Transaction failed
- if(t instanceof OptimisticLockFailedException) {
- // Failed because of concurrent transaction modifying same data
- s_logger.error( "Delete Flow -- Failed because of concurrent transaction modifying same data ") ;
- } else {
- // Some other type of TransactionCommitFailedException
- s_logger.error( "Delete Flow -- Some other type of TransactionCommitFailedException " + t) ;
- }
+ @Override
+ public void onFailure(final Throwable throwable) {
+ // Transaction failed
+ if (throwable instanceof OptimisticLockFailedException) {
+ // Failed because of concurrent transaction modifying same
+ // data
+ LOG.error("Delete Flow -- Failed because of concurrent transaction modifying same data");
+ } else {
+ // Some other type of TransactionCommitFailedException
+ LOG.error("Delete Flow -- Some other type of TransactionCommitFailedException", throwable);
}
+ }
- });
+ });
- return submitFuture;
+ return submitFuture;
}
public void deleteFlowEntityInternal(FlowEntity flowEntity, WriteTransaction tx) {
.child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class)
.child(Table.class, new TableKey(flowEntity.getTableId())).child(Flow.class, flowKey).build();
-
- tx.delete(LogicalDatastoreType.CONFIGURATION,flowInstanceId);
+ tx.delete(LogicalDatastoreType.CONFIGURATION, flowInstanceId);
}
- public CheckedFuture<Void,TransactionCommitFailedException> removeFlowNewInternal(BigInteger dpnId, Flow flowEntity) {
- s_logger.debug("Remove flow {}",flowEntity);
- WriteTransaction tx = m_dataBroker.newWriteOnlyTransaction();
+ public CheckedFuture<Void, TransactionCommitFailedException> removeFlowNewInternal(BigInteger dpnId,
+ Flow flowEntity) {
+ LOG.debug("Remove flow {}", flowEntity);
+ WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
deleteFlowInternal(dpnId, flowEntity, tx);
return tx.submit();
}
InstanceIdentifier<Flow> flowInstanceId = InstanceIdentifier.builder(Nodes.class)
.child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class)
.child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flowKey).build();
- tx.delete(LogicalDatastoreType.CONFIGURATION,flowInstanceId );
+ tx.delete(LogicalDatastoreType.CONFIGURATION, flowInstanceId);
}
public CheckedFuture<Void, TransactionCommitFailedException> removeGroupInternal(GroupEntity groupEntity) {
- WriteTransaction tx = m_dataBroker.newWriteOnlyTransaction();
- removeGroupEntityInternal(groupEntity, tx);
+ WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
+ removeGroupEntityInternal(groupEntity, tx);
- CheckedFuture<Void,TransactionCommitFailedException> submitFuture = tx.submit();
+ CheckedFuture<Void, TransactionCommitFailedException> submitFuture = tx.submit();
- Futures.addCallback(submitFuture, new FutureCallback<Void>() {
- @Override
- public void onSuccess(final Void result) {
- // Commited successfully
- s_logger.debug( "Install Group -- Committedsuccessfully ") ;
- }
+ Futures.addCallback(submitFuture, new FutureCallback<Void>() {
+ @Override
+ public void onSuccess(final Void result) {
+ // Committed successfully
+ LOG.debug("Install Group -- Committedsuccessfully ");
+ }
- @Override
- public void onFailure(final Throwable t) {
- // Transaction failed
- if(t instanceof OptimisticLockFailedException) {
- // Failed because of concurrent transaction modifying same data
- s_logger.error( "Install Group -- Failed because of concurrent transaction modifying same data ") ;
- } else {
- // Some other type of TransactionCommitFailedException
- s_logger.error( "Install Group -- Some other type of TransactionCommitFailedException " + t) ;
- }
+ @Override
+ public void onFailure(final Throwable throwable) {
+ // Transaction failed
+ if (throwable instanceof OptimisticLockFailedException) {
+ // Failed because of concurrent transaction modifying same
+ // data
+ LOG.error("Install Group -- Failed because of concurrent transaction modifying same data");
+ } else {
+ // Some other type of TransactionCommitFailedException
+ LOG.error("Install Group -- Some other type of TransactionCommitFailedException", throwable);
}
- });
+ }
+ });
- return submitFuture;
+ return submitFuture;
}
public void removeGroupEntityInternal(GroupEntity groupEntity, WriteTransaction tx) {
.child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class)
.child(Group.class, new GroupKey(new GroupId(groupEntity.getGroupId()))).build();
- tx.delete(LogicalDatastoreType.CONFIGURATION,groupInstanceId );
+ tx.delete(LogicalDatastoreType.CONFIGURATION, groupInstanceId);
}
public void modifyGroupInternal(GroupEntity groupEntity) {
sendPacketOutWithActions(dpnId, groupId, payload, actionInfos);
}
- public void sendPacketOutWithActionsInternal(BigInteger dpnId, long groupId, byte[] payload, List<ActionInfo> actionInfos) {
+ public void sendPacketOutWithActionsInternal(BigInteger dpnId, long groupId, byte[] payload,
+ List<ActionInfo> actionInfos) {
- m_packetProcessingService.transmitPacket(MDSALUtil.getPacketOut(actionInfos, payload, dpnId,
- getNodeConnRef("openflow:" + dpnId, "0xfffffffd")));
+ packetProcessingService.transmitPacket(
+ MDSALUtil.getPacketOut(actionInfos, payload, dpnId, getNodeConnRef("openflow:" + dpnId, "0xfffffffd")));
}
public void sendARPPacketOutWithActionsInternal(BigInteger dpnId, byte[] payload, List<ActionInfo> actions) {
- m_packetProcessingService.transmitPacket(MDSALUtil.getPacketOut(actions, payload, dpnId,
- getNodeConnRef("openflow:" + dpnId, "0xfffffffd")));
+ packetProcessingService.transmitPacket(
+ MDSALUtil.getPacketOut(actions, payload, dpnId, getNodeConnRef("openflow:" + dpnId, "0xfffffffd")));
}
protected InstanceIdentifier<Node> nodeToInstanceId(Node node) {
}
protected static NodeConnectorRef getNodeConnRef(final String nodeId, final String port) {
- StringBuilder _stringBuilder = new StringBuilder(nodeId);
- StringBuilder _append = _stringBuilder.append(":");
- StringBuilder sBuild = _append.append(port);
- String _string = sBuild.toString();
- NodeConnectorId _nodeConnectorId = new NodeConnectorId(_string);
- NodeConnectorKey _nodeConnectorKey = new NodeConnectorKey(_nodeConnectorId);
- NodeConnectorKey nConKey = _nodeConnectorKey;
- InstanceIdentifierBuilder<Nodes> _builder = InstanceIdentifier.builder(Nodes.class);
- NodeId _nodeId = new NodeId(nodeId);
- NodeKey _nodeKey = new NodeKey(_nodeId);
- InstanceIdentifierBuilder<Node> _child = _builder.child(Node.class, _nodeKey);
- InstanceIdentifierBuilder<NodeConnector> _child_1 = _child.child(
- NodeConnector.class, nConKey);
- InstanceIdentifier<NodeConnector> path = _child_1.toInstance();
- NodeConnectorRef _nodeConnectorRef = new NodeConnectorRef(path);
- return _nodeConnectorRef;
+ StringBuilder stringBuilder = new StringBuilder(nodeId);
+ StringBuilder append = stringBuilder.append(":");
+ StringBuilder build = append.append(port);
+ String string = build.toString();
+ NodeConnectorId nodeConnectorId = new NodeConnectorId(string);
+ NodeConnectorKey nodeConnectorKey = new NodeConnectorKey(nodeConnectorId);
+ NodeConnectorKey connectorKey = nodeConnectorKey;
+ InstanceIdentifierBuilder<Nodes> builder = InstanceIdentifier.builder(Nodes.class);
+
+ NodeKey nodeKey = new NodeKey(new NodeId(nodeId));
+ InstanceIdentifierBuilder<Node> child = builder.child(Node.class, nodeKey);
+ InstanceIdentifierBuilder<NodeConnector> anotherChild = child.child(NodeConnector.class, connectorKey);
+ InstanceIdentifier<NodeConnector> path = anotherChild.toInstance();
+ NodeConnectorRef nodeConnectorRef = new NodeConnectorRef(path);
+ return nodeConnectorRef;
}
protected Node buildDpnNode(BigInteger dpnId) {
}
public void syncSetUpFlowInternal(FlowEntity flowEntity, long delay, boolean isRemove) {
- if (s_logger.isTraceEnabled()) {
- s_logger.trace("syncSetUpFlow for flowEntity {} ", flowEntity);
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("syncSetUpFlow for flowEntity {} ", flowEntity);
}
if (flowEntity.getCookie() == null) {
flowEntity.setCookie(new BigInteger("0110000", 16));
Flow flow = flowEntity.getFlowBuilder().build();
String flowId = flowEntity.getFlowId();
BigInteger dpId = flowEntity.getDpnId();
- FlowKey flowKey = new FlowKey( new FlowId(flowId));
+ FlowKey flowKey = new FlowKey(new FlowId(flowId));
Node nodeDpn = buildDpnNode(dpId);
InstanceIdentifier<Flow> flowInstanceId = InstanceIdentifier.builder(Nodes.class)
.child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class)
.child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flowKey).build();
if (isRemove) {
- MDSALUtil.syncDelete(m_dataBroker, LogicalDatastoreType.CONFIGURATION, flowInstanceId);
+ MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, flowInstanceId);
} else {
- MDSALUtil.syncWrite(m_dataBroker, LogicalDatastoreType.CONFIGURATION, flowInstanceId, flow);
+ MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, flowInstanceId, flow);
}
}
public void syncSetUpGroupInternal(GroupEntity groupEntity, long delayTime, boolean isRemove) {
- if (s_logger.isTraceEnabled()) {
- s_logger.trace("syncSetUpGroup for groupEntity {} ", groupEntity);
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("syncSetUpGroup for groupEntity {} ", groupEntity);
}
Group group = groupEntity.getGroupBuilder().build();
BigInteger dpId = groupEntity.getDpnId();
long groupId = groupEntity.getGroupId();
GroupKey groupKey = new GroupKey(new GroupId(groupId));
InstanceIdentifier<Group> groupInstanceId = InstanceIdentifier.builder(Nodes.class)
- .child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class)
- .child(Group.class, groupKey).build();
+ .child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class).child(Group.class, groupKey)
+ .build();
if (isRemove) {
- MDSALUtil.syncDelete(m_dataBroker, LogicalDatastoreType.CONFIGURATION, groupInstanceId);
+ MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, groupInstanceId);
} else {
- MDSALUtil.syncWrite(m_dataBroker, LogicalDatastoreType.CONFIGURATION, groupInstanceId, group);
+ MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, groupInstanceId, group);
}
}
public void syncSetUpGroupInternal(BigInteger dpId, Group group, long delayTime, boolean isRemove) {
- s_logger.trace("syncSetUpGroup for group {} ", group);
+ LOG.trace("syncSetUpGroup for group {} ", group);
Node nodeDpn = buildDpnNode(dpId);
long groupId = group.getGroupId().getValue();
GroupKey groupKey = new GroupKey(new GroupId(groupId));
InstanceIdentifier<Group> groupInstanceId = InstanceIdentifier.builder(Nodes.class)
- .child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class)
- .child(Group.class, groupKey).build();
+ .child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class).child(Group.class, groupKey)
+ .build();
if (isRemove) {
- MDSALUtil.syncDelete(m_dataBroker, LogicalDatastoreType.CONFIGURATION, groupInstanceId);
+ MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, groupInstanceId);
} else {
- MDSALUtil.syncWrite(m_dataBroker, LogicalDatastoreType.CONFIGURATION, groupInstanceId, group);
+ MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, groupInstanceId, group);
}
}
- class GroupListener extends AsyncClusteredDataChangeListenerBase<Group,GroupListener> {
+ class GroupListener extends AsyncClusteredDataChangeListenerBase<Group, GroupListener> {
- public GroupListener() {
- super(Group.class,GroupListener.class);
+ GroupListener() {
+ super(Group.class, GroupListener.class);
}
@Override
@Override
protected InstanceIdentifier<Group> getWildCardPath() {
- return InstanceIdentifier.create(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class).child(Group.class);
+ return InstanceIdentifier.create(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class)
+ .child(Group.class);
}
@Override
}
}
- class FlowListener extends AsyncClusteredDataChangeListenerBase<Flow,FlowListener> {
+ class FlowListener extends AsyncClusteredDataChangeListenerBase<Flow, FlowListener> {
- public FlowListener() {
+ FlowListener() {
super(Flow.class, FlowListener.class);
}
@Override
protected InstanceIdentifier<Flow> getWildCardPath() {
- return InstanceIdentifier.create(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class).child(Table.class).child(Flow.class);
+ return InstanceIdentifier.create(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class)
+ .child(Table.class).child(Flow.class);
}
@Override
modifyGroupInternal(groupEntity);
}
-
@Override
public void removeGroup(GroupEntity groupEntity) {
removeGroupInternal(groupEntity);
sendPacketOutInternal(dpnId, groupId, payload);
}
-
@Override
- public void sendPacketOutWithActions(BigInteger dpnId, long groupId,
- byte[] payload, List<ActionInfo> actionInfos) {
+ public void sendPacketOutWithActions(BigInteger dpnId, long groupId, byte[] payload, List<ActionInfo> actionInfos) {
sendPacketOutWithActionsInternal(dpnId, groupId, payload, actionInfos);
}
-
@Override
- public void sendARPPacketOutWithActions(BigInteger dpnId, byte[] payload,
- List<ActionInfo> actionInfo) {
+ public void sendARPPacketOutWithActions(BigInteger dpnId, byte[] payload, List<ActionInfo> actionInfo) {
sendARPPacketOutWithActionsInternal(dpnId, payload, actionInfo);
}
@Override
public void syncRemoveFlow(FlowEntity flowEntity, long delayTime) {
- syncSetUpFlowInternal(flowEntity, delayTime, true);
+ syncSetUpFlowInternal(flowEntity, delayTime, true);
}
@Override
/*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
package org.opendaylight.genius.mdsalutil.internal;
+import java.util.List;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import java.util.List;
-
public class MdSalUtilBatchHandler implements ResourceHandler {
- public void update(WriteTransaction tx, LogicalDatastoreType datastoreType, InstanceIdentifier identifier, Object original, Object update,List<SubTransaction> transactionObjects) {
+ @Override
+ public void update(WriteTransaction tx, LogicalDatastoreType datastoreType, InstanceIdentifier identifier,
+ Object original, Object update, List<SubTransaction> transactionObjects) {
if (update != null && !(update instanceof DataObject)) {
return;
}
if (datastoreType != this.getDatastoreType()) {
return;
}
- tx.merge(datastoreType, identifier, (DataObject)update, true);
+ tx.merge(datastoreType, identifier, (DataObject) update, true);
buildSubTransactions(transactionObjects, identifier, update, SubTransaction.UPDATE);
}
- public void create(WriteTransaction tx, LogicalDatastoreType datastoreType, InstanceIdentifier identifier, Object data,List<SubTransaction> transactionObjects) {
+ @Override
+ public void create(WriteTransaction tx, LogicalDatastoreType datastoreType, InstanceIdentifier identifier,
+ Object data, List<SubTransaction> transactionObjects) {
if (data != null && !(data instanceof DataObject)) {
return;
}
if (datastoreType != this.getDatastoreType()) {
return;
}
- tx.put(datastoreType, identifier, (DataObject)data, true);
+ tx.put(datastoreType, identifier, (DataObject) data, true);
buildSubTransactions(transactionObjects, identifier, data, SubTransaction.CREATE);
}
- public void delete(WriteTransaction tx, LogicalDatastoreType datastoreType, InstanceIdentifier identifier, Object data,List<SubTransaction> transactionObjects) {
+ @Override
+ public void delete(WriteTransaction tx, LogicalDatastoreType datastoreType, InstanceIdentifier identifier,
+ Object data, List<SubTransaction> transactionObjects) {
if (data != null && !(data instanceof DataObject)) {
return;
}
buildSubTransactions(transactionObjects, identifier, data, SubTransaction.DELETE);
}
+ @Override
public DataBroker getResourceBroker() {
return FlowBatchingUtils.getBroker();
}
+ @Override
public int getBatchSize() {
return FlowBatchingUtils.batchSize;
}
+ @Override
public int getBatchInterval() {
return FlowBatchingUtils.batchInterval;
}
+ @Override
public LogicalDatastoreType getDatastoreType() {
return LogicalDatastoreType.CONFIGURATION;
}
private void buildSubTransactions(List<SubTransaction> transactionObjects, InstanceIdentifier identifier,
- Object data, short subTransactionType) {
+ Object data, short subTransactionType) {
// enable retries
SubTransaction subTransaction = new SubTransactionImpl();
subTransaction.setInstanceIdentifier(identifier);
/*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
import org.slf4j.LoggerFactory;
class NotifyTask implements Runnable {
- private static final Logger logger = LoggerFactory.getLogger(NotifyTask.class);
+ private static final Logger LOG = LoggerFactory.getLogger(NotifyTask.class);
@Override
public void run() {
- logger.debug("Notify Task is running for the task {}", this);
+ LOG.debug("Notify Task is running for the task {}", this);
synchronized (this) {
notifyAll();
}
}
-
}
/*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
import java.util.Collection;
-import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
-import com.google.common.base.Preconditions;
public abstract class AbstractMockForwardingRulesManager<D extends DataObject> implements DataTreeChangeListener<D> {
// Do Nothing
}
-
+ @Override
public void onDataTreeChanged(Collection<DataTreeModification<D>> changes) {
// TODO Auto-generated method stub
}
-
}
*/
package org.opendaylight.genius.test;
+import static org.junit.Assert.assertEquals;
+
import java.math.BigInteger;
import java.util.ArrayList;
-import java.util.List;
import java.util.Collections;
+import java.util.List;
import java.util.concurrent.ExecutionException;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-
import org.mockito.runners.MockitoJUnitRunner;
-import org.opendaylight.genius.mdsalutil.actions.ActionOutput;
-import org.opendaylight.genius.mdsalutil.actions.ActionPuntToController;
-import org.opendaylight.genius.mdsalutil.actions.ActionPushVlan;
-import org.opendaylight.genius.mdsalutil.actions.ActionSetFieldVlanVid;
-import org.opendaylight.genius.mdsalutil.instructions.InstructionWriteActions;
-import org.opendaylight.genius.mdsalutil.matches.MatchTunnelId;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.genius.mdsalutil.ActionInfo;
+import org.opendaylight.genius.mdsalutil.BucketInfo;
import org.opendaylight.genius.mdsalutil.FlowEntity;
import org.opendaylight.genius.mdsalutil.GroupEntity;
-import org.opendaylight.genius.mdsalutil.BucketInfo;
import org.opendaylight.genius.mdsalutil.InstructionInfo;
import org.opendaylight.genius.mdsalutil.MDSALUtil;
import org.opendaylight.genius.mdsalutil.MatchInfo;
+import org.opendaylight.genius.mdsalutil.actions.ActionOutput;
+import org.opendaylight.genius.mdsalutil.actions.ActionPuntToController;
+import org.opendaylight.genius.mdsalutil.actions.ActionPushVlan;
+import org.opendaylight.genius.mdsalutil.actions.ActionSetFieldVlanVid;
+import org.opendaylight.genius.mdsalutil.instructions.InstructionWriteActions;
import org.opendaylight.genius.mdsalutil.internal.MDSALManager;
+import org.opendaylight.genius.mdsalutil.matches.MatchTunnelId;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupTypes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
-import static org.junit.Assert.assertEquals;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
@RunWith(MockitoJUnitRunner.class)
@PrepareForTest(MDSALUtil.class)
public class MdSalUtilTest extends AbstractConcurrentDataBrokerTest {
- DataBroker dataBroker;
- @Mock PacketProcessingService ppS ;
- MDSALManager mdSalMgr = null ;
- MockFlowForwarder flowFwder = null ;
- MockGroupForwarder grpFwder = null ;
- private static final String Nodeid = "openflow:1";
-
- @Before
- public void setUp() throws Exception {
- dataBroker = getDataBroker() ;
- mdSalMgr = new MDSALManager( dataBroker, ppS);
- flowFwder = new MockFlowForwarder( dataBroker );
- grpFwder = new MockGroupForwarder( dataBroker ) ;
-
- PowerMockito.mockStatic(MDSALUtil.class) ;
-
- NodeKey s1Key = new NodeKey(new NodeId("openflow:1"));
- addFlowCapableNode(s1Key);
- }
-
- @Test
- public void testInstallFlow() throws Exception {
- String dpnId = "openflow:1";
- String tableId1 = "12";
-
- //Install Flow 1
- FlowEntity testFlow1 = createFlowEntity(dpnId, tableId1) ;
- mdSalMgr.installFlowInternal(testFlow1).get();
- assertEquals(1, flowFwder.getDataChgCount());
-
- // Install FLow 2
- String tableId2 = "13" ;
- FlowEntity testFlow2 = createFlowEntity(dpnId, tableId2) ;
- mdSalMgr.installFlowInternal(testFlow2).get();
- assertEquals(2, flowFwder.getDataChgCount());
- }
+ DataBroker dataBroker;
+ @Mock
+ PacketProcessingService ppS;
+ MDSALManager mdSalMgr = null;
+ MockFlowForwarder flowFwder = null;
+ MockGroupForwarder grpFwder = null;
+ private static final String NODE_ID = "openflow:1";
+
+ @Before
+ public void setUp() throws Exception {
+ dataBroker = getDataBroker();
+ mdSalMgr = new MDSALManager(dataBroker, ppS);
+ flowFwder = new MockFlowForwarder(dataBroker);
+ grpFwder = new MockGroupForwarder(dataBroker);
+
+ PowerMockito.mockStatic(MDSALUtil.class);
+
+ NodeKey s1Key = new NodeKey(new NodeId("openflow:1"));
+ addFlowCapableNode(s1Key);
+ }
- @Test
- public void testRemoveFlow() throws Exception {
- String dpnId = "openflow:1";
- String tableId = "13" ;
- FlowEntity testFlow = createFlowEntity(dpnId, tableId) ;
-
- // To test RemoveFlow add and then delete Flows
- mdSalMgr.installFlowInternal(testFlow).get();
- assertEquals(1, flowFwder.getDataChgCount());
- mdSalMgr.removeFlowInternal(testFlow).get();
- assertEquals(0, flowFwder.getDataChgCount());
- }
+ @Test
+ public void testInstallFlow() throws Exception {
+ String dpnId = "openflow:1";
+ String tableId1 = "12";
+
+ // Install Flow 1
+ FlowEntity testFlow1 = createFlowEntity(dpnId, tableId1);
+ mdSalMgr.installFlowInternal(testFlow1).get();
+ assertEquals(1, flowFwder.getDataChgCount());
+
+ // Install FLow 2
+ String tableId2 = "13";
+ FlowEntity testFlow2 = createFlowEntity(dpnId, tableId2);
+ mdSalMgr.installFlowInternal(testFlow2).get();
+ assertEquals(2, flowFwder.getDataChgCount());
+ }
- @Test
- public void testInstallGroup() throws Exception {
- // Install Group 1
- String inport = "2" ;
- int vlanid = 100 ;
- GroupEntity grpEntity1 = createGroupEntity(Nodeid, inport, vlanid) ;
-
- mdSalMgr.installGroupInternal(grpEntity1).get();
- assertEquals(1, grpFwder.getDataChgCount());
-
- // Install Group 2
- inport = "3" ;
- vlanid = 100 ;
- GroupEntity grpEntity2 = createGroupEntity(Nodeid, inport, vlanid) ;
- mdSalMgr.installGroupInternal(grpEntity2).get();
- assertEquals(2, grpFwder.getDataChgCount());
- }
+ @Test
+ public void testRemoveFlow() throws Exception {
+ String dpnId = "openflow:1";
+ String tableId = "13";
+ FlowEntity testFlow = createFlowEntity(dpnId, tableId);
+
+ // To test RemoveFlow add and then delete Flows
+ mdSalMgr.installFlowInternal(testFlow).get();
+ assertEquals(1, flowFwder.getDataChgCount());
+ mdSalMgr.removeFlowInternal(testFlow).get();
+ assertEquals(0, flowFwder.getDataChgCount());
+ }
- @Test
- public void testRemoveGroup() throws Exception {
- String inport = "2" ;
- int vlanid = 100 ;
- GroupEntity grpEntity = createGroupEntity(Nodeid, inport, vlanid) ;
- // To test RemoveGroup add and then delete Group
- mdSalMgr.installGroupInternal(grpEntity).get();
- assertEquals(1, grpFwder.getDataChgCount());
- mdSalMgr.removeGroupInternal(grpEntity).get();
- assertEquals(0, grpFwder.getDataChgCount());
- }
+ @Test
+ public void testInstallGroup() throws Exception {
+ // Install Group 1
+ String inport = "2";
+ int vlanid = 100;
+ GroupEntity grpEntity1 = createGroupEntity(NODE_ID, inport, vlanid);
+
+ mdSalMgr.installGroupInternal(grpEntity1).get();
+ assertEquals(1, grpFwder.getDataChgCount());
+
+ // Install Group 2
+ inport = "3";
+ vlanid = 100;
+ GroupEntity grpEntity2 = createGroupEntity(NODE_ID, inport, vlanid);
+ mdSalMgr.installGroupInternal(grpEntity2).get();
+ assertEquals(2, grpFwder.getDataChgCount());
+ }
- public void addFlowCapableNode(NodeKey nodeKey) throws ExecutionException, InterruptedException {
- Nodes nodes = new NodesBuilder().setNode(Collections.emptyList()).build();
- InstanceIdentifier<Node> flowNodeIdentifier = InstanceIdentifier.create(Nodes.class)
- .child(Node.class, nodeKey);
-
- FlowCapableNodeBuilder fcnBuilder = new FlowCapableNodeBuilder();
- NodeBuilder nodeBuilder = new NodeBuilder();
- nodeBuilder.setKey(nodeKey);
- nodeBuilder.addAugmentation(FlowCapableNode.class, fcnBuilder.build());
-
- WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
- writeTx.put(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(Nodes.class), nodes);
- writeTx.put(LogicalDatastoreType.OPERATIONAL, flowNodeIdentifier, nodeBuilder.build());
- writeTx.put(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(Nodes.class), nodes);
- writeTx.put(LogicalDatastoreType.CONFIGURATION, flowNodeIdentifier, nodeBuilder.build());
- assertCommit(writeTx.submit());
- }
+ @Test
+ public void testRemoveGroup() throws Exception {
+ String inport = "2";
+ int vlanid = 100;
+ GroupEntity grpEntity = createGroupEntity(NODE_ID, inport, vlanid);
+ // To test RemoveGroup add and then delete Group
+ mdSalMgr.installGroupInternal(grpEntity).get();
+ assertEquals(1, grpFwder.getDataChgCount());
+ mdSalMgr.removeGroupInternal(grpEntity).get();
+ assertEquals(0, grpFwder.getDataChgCount());
+ }
- // Methods to test the install Flow and Group
+ public void addFlowCapableNode(NodeKey nodeKey) throws ExecutionException, InterruptedException {
+ Nodes nodes = new NodesBuilder().setNode(Collections.emptyList()).build();
+ final InstanceIdentifier<Node> flowNodeIdentifier = InstanceIdentifier.create(Nodes.class).child(Node.class,
+ nodeKey);
+
+ FlowCapableNodeBuilder fcnBuilder = new FlowCapableNodeBuilder();
+ NodeBuilder nodeBuilder = new NodeBuilder();
+ nodeBuilder.setKey(nodeKey);
+ nodeBuilder.addAugmentation(FlowCapableNode.class, fcnBuilder.build());
+
+ WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
+ writeTx.put(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(Nodes.class), nodes);
+ writeTx.put(LogicalDatastoreType.OPERATIONAL, flowNodeIdentifier, nodeBuilder.build());
+ writeTx.put(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(Nodes.class), nodes);
+ writeTx.put(LogicalDatastoreType.CONFIGURATION, flowNodeIdentifier, nodeBuilder.build());
+ assertCommit(writeTx.submit());
+ }
- public FlowEntity createFlowEntity(String dpnId, String tableId) {
+ // Methods to test the install Flow and Group
+ public FlowEntity createFlowEntity(String dpnId, String tableId) {
+ BigInteger dpId;
+ final int serviceId = 0;
- BigInteger dpId;
- int SERVICE_ID = 0;
- FlowEntity terminatingServiceTableFlowEntity = null;
+ List<ActionInfo> listActionInfo = new ArrayList<>();
+ listActionInfo.add(new ActionPuntToController());
- List<ActionInfo> listActionInfo = new ArrayList<>();
- listActionInfo.add(new ActionPuntToController());
+ dpId = new BigInteger(dpnId.split(":")[1]);
- try {
- dpId = new BigInteger(dpnId.split(":")[1]);
+ List<MatchInfo> mkMatches = new ArrayList<>();
+ final BigInteger cookie = new BigInteger("9000000", 16);
- List<MatchInfo> mkMatches = new ArrayList<>();
- BigInteger COOKIE = new BigInteger("9000000", 16);
+ short shortTableId = Short.parseShort(tableId);
- short s_tableId = Short.parseShort(tableId) ;
+ mkMatches.add(new MatchTunnelId(new BigInteger("0000000000000000", 16)));
- mkMatches.add(new MatchTunnelId(new BigInteger("0000000000000000", 16)));
+ List<InstructionInfo> mkInstructions = new ArrayList<>();
+ mkInstructions.add(new InstructionWriteActions(listActionInfo));
- List<InstructionInfo> mkInstructions = new ArrayList<>();
- mkInstructions.add(new InstructionWriteActions(listActionInfo));
+ FlowEntity terminatingServiceTableFlowEntity = MDSALUtil.buildFlowEntity(dpId, shortTableId,
+ getFlowRef(shortTableId, serviceId), 5, "Terminating Service Flow Entry: " + serviceId, 0, 0,
+ cookie.add(BigInteger.valueOf(serviceId)), null, null);
- terminatingServiceTableFlowEntity = MDSALUtil
- .buildFlowEntity(
- dpId,
- s_tableId,
- getFlowRef(s_tableId,
- SERVICE_ID), 5, "Terminating Service Flow Entry: " + SERVICE_ID,
- 0, 0, COOKIE
- .add(BigInteger.valueOf(SERVICE_ID)),
- null, null);
- } catch (Exception e) {
- //throw new Exception(e) ;
- }
+ return terminatingServiceTableFlowEntity;
+ }
- return terminatingServiceTableFlowEntity;
- }
+ private String getFlowRef(short termSvcTable, int svcId) {
+ return String.valueOf(termSvcTable) + svcId;
+ }
- private String getFlowRef(short termSvcTable, int svcId) {
- return String.valueOf(termSvcTable) + svcId;
+ public GroupEntity createGroupEntity(String nodeid, String inport, int vlanid) {
+ List<BucketInfo> listBucketInfo = new ArrayList<>();
+ List<ActionInfo> listActionInfo = new ArrayList<>();
+ if (vlanid > 0) {
+ listActionInfo.add(new ActionPushVlan());
+ listActionInfo.add(new ActionSetFieldVlanVid(vlanid));
}
+ listActionInfo.add(new ActionOutput(new Uri(inport), 65535));
+ listBucketInfo.add(new BucketInfo(listActionInfo));
- public GroupEntity createGroupEntity(String Nodeid, String inport, int vlanid) {
- GroupEntity groupEntity;
- long id = getUniqueValue(Nodeid, inport);
- List<BucketInfo> listBucketInfo = new ArrayList<>();
- List<ActionInfo> listActionInfo = new ArrayList<>();
- if (vlanid > 0) {
- listActionInfo.add(new ActionPushVlan());
- listActionInfo.add(new ActionSetFieldVlanVid(vlanid));
- }
- listActionInfo.add(new ActionOutput(new Uri(inport), 65535));
- listBucketInfo.add(new BucketInfo(listActionInfo));
-
- String groupName = "Test Group";
- BigInteger dpnId = new BigInteger(Nodeid.split(":")[1]);
- groupEntity = MDSALUtil.buildGroupEntity(dpnId, id, groupName, GroupTypes.GroupIndirect,
- listBucketInfo);
-
- return groupEntity;
- }
+ String groupName = "Test Group";
+ BigInteger dpnId = new BigInteger(nodeid.split(":")[1]);
- private static long getUniqueValue(String nodeId, String inport) {
+ long id = getUniqueValue(nodeid, inport);
+ return MDSALUtil.buildGroupEntity(dpnId, id, groupName, GroupTypes.GroupIndirect, listBucketInfo);
+ }
- Long nodeIdL = Long.valueOf(nodeId.split(":")[1]);
- Long inportL = Long.valueOf(inport);
- long sd_set;
- sd_set = nodeIdL * 10 + inportL;
+ private static long getUniqueValue(String nodeId, String inport) {
+ Long nodeIdL = Long.valueOf(nodeId.split(":")[1]);
+ Long inportL = Long.valueOf(inport);
+ long sdSet = nodeIdL * 10 + inportL;
- return sd_set;
+ return sdSet;
}
-
}
/*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
package org.opendaylight.genius.test;
import java.util.Collection;
-
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
public class MockFlowForwarder extends AbstractMockForwardingRulesManager<Flow> {
- private int nFlowCount = 0;
+ private int flowCount = 0;
private ListenerRegistration<MockFlowForwarder> listenerRegistration;
- public MockFlowForwarder( final DataBroker db) {
- super() ;
- registerListener(db) ;
+ public MockFlowForwarder(final DataBroker db) {
+ super();
+ registerListener(db);
}
private void registerListener(final DataBroker db) {
- final DataTreeIdentifier<Flow> treeId = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, getWildCardPath());
- try {
- listenerRegistration = db.registerDataTreeChangeListener(treeId, MockFlowForwarder.this);
- } catch (final Exception e) {
- throw new IllegalStateException("FlowForwarder registration Listener fail! System needs restart.", e);
- }
+ final DataTreeIdentifier<Flow> treeId = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION,
+ getWildCardPath());
+ listenerRegistration = db.registerDataTreeChangeListener(treeId, MockFlowForwarder.this);
}
private InstanceIdentifier<Flow> getWildCardPath() {
- return InstanceIdentifier.create(Nodes.class).child(Node.class)
- .augmentation(FlowCapableNode.class).child(Table.class).child(Flow.class);
- }
+ return InstanceIdentifier.create(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class)
+ .child(Table.class).child(Flow.class);
+ }
@Override
public void onDataTreeChanged(Collection<DataTreeModification<Flow>> changes) {
final InstanceIdentifier<Flow> key = change.getRootPath().getRootIdentifier();
final DataObjectModification<Flow> mod = change.getRootNode();
- switch (mod.getModificationType()) {
+ switch (mod.getModificationType()) {
case DELETE:
- nFlowCount -= 1;
+ flowCount -= 1;
break;
case SUBTREE_MODIFIED:
// CHECK IF RQD
break;
case WRITE:
if (mod.getDataBefore() == null) {
- nFlowCount += 1;
+ flowCount += 1;
} else {
// UPDATE COUNT UNCHANGED
}
break;
default:
throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());
- }
}
- }
+ }
+ }
public int getDataChgCount() {
- return nFlowCount;
+ return flowCount;
}
}
/*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
package org.opendaylight.genius.test;
import java.util.Collection;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
-public class MockGroupForwarder extends AbstractMockForwardingRulesManager<Group>{
+public class MockGroupForwarder extends AbstractMockForwardingRulesManager<Group> {
- private int nGroupCount = 0;
- private ListenerRegistration<MockGroupForwarder> listenerRegistration ;
+ private int groupCount = 0;
+ private ListenerRegistration<MockGroupForwarder> listenerRegistration;
- public MockGroupForwarder( final DataBroker db) {
- super() ;
- registerListener(db) ;
+ public MockGroupForwarder(final DataBroker db) {
+ super();
+ registerListener(db);
}
private void registerListener(final DataBroker db) {
- final DataTreeIdentifier<Group> treeId = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, getWildCardPath());
- try {
- listenerRegistration = db.registerDataTreeChangeListener(treeId, MockGroupForwarder.this);
- } catch (final Exception e) {
- throw new IllegalStateException("GroupForwarder registration Listener fail! System needs restart.", e);
- }
+ final DataTreeIdentifier<Group> treeId = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION,
+ getWildCardPath());
+ listenerRegistration = db.registerDataTreeChangeListener(treeId, MockGroupForwarder.this);
}
private InstanceIdentifier<Group> getWildCardPath() {
- return InstanceIdentifier.create(Nodes.class).child(Node.class).
- augmentation(FlowCapableNode.class).child(Group.class);
+ return InstanceIdentifier.create(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class)
+ .child(Group.class);
}
@Override
final InstanceIdentifier<Group> key = change.getRootPath().getRootIdentifier();
final DataObjectModification<Group> mod = change.getRootNode();
- switch (mod.getModificationType()) {
+ switch (mod.getModificationType()) {
case DELETE:
- nGroupCount -= 1;
+ groupCount -= 1;
break;
case SUBTREE_MODIFIED:
// CHECK IF RQD
break;
case WRITE:
if (mod.getDataBefore() == null) {
- nGroupCount += 1;
+ groupCount += 1;
} else {
// UPDATE COUNT UNCHANGED
}
break;
default:
throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());
- }
}
- }
+ }
+ }
public int getDataChgCount() {
- return nGroupCount;
+ return groupCount;
}
}