<artifactId>nexthopmgr-api</artifactId>
<version>${vpnservices.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.openflowplugin.model</groupId>
+ <artifactId>model-flow-service</artifactId>
+ <version>${openflowplugin.version}</version>
+ </dependency>
</dependencies>
</project>
}
return vpnId;
}
+
+ public void processNodeAdd(long dpnId) {
+ LOG.debug("Received notification to install TableMiss entries for dpn {} ", dpnId);
+ makeTableMissFlow(dpnId, NwConstants.ADD_FLOW);
+ }
+
+ private void makeTableMissFlow(long dpnId, int addOrRemove) {
+ final BigInteger COOKIE_TABLE_MISS = new BigInteger("1030000", 16);
+ // Instruction to punt to controller
+ List<InstructionInfo> instructions = new ArrayList<InstructionInfo>();
+ List<ActionInfo> actionsInfos = new ArrayList<ActionInfo>();
+ actionsInfos.add(new ActionInfo(ActionType.punt_to_controller, new String[] {}));
+ instructions.add(new InstructionInfo(InstructionType.write_actions, actionsInfos));
+ List<MatchInfo> matches = new ArrayList<MatchInfo>();
+ FlowEntity flowEntityLfib = MDSALUtil.buildFlowEntity(dpnId, L3_LFIB_TABLE,
+ getFlowRef(dpnId, L3_LFIB_TABLE, NwConstants.TABLE_MISS_FLOW),
+ NwConstants.TABLE_MISS_PRIORITY, "Table Miss", 0, 0, COOKIE_TABLE_MISS, matches, instructions);
+
+ FlowEntity flowEntityFib = MDSALUtil.buildFlowEntity(dpnId,L3_FIB_TABLE, getFlowRef(dpnId, L3_FIB_TABLE, NwConstants.TABLE_MISS_FLOW),
+ NwConstants.TABLE_MISS_PRIORITY, "FIB Table Miss Flow", 0, 0, COOKIE_VM_FIB_TABLE,
+ matches, instructions);
+
+ if (addOrRemove == NwConstants.ADD_FLOW) {
+ LOG.debug("Invoking MDSAL to install Table Miss Entries");
+ mdsalManager.installFlow(flowEntityLfib);
+ mdsalManager.installFlow(flowEntityFib);
+ } else {
+ mdsalManager.removeFlow(flowEntityLfib);
+ mdsalManager.removeFlow(flowEntityFib);
+
+ }
+ }
+
+ private String getFlowRef(long dpnId, short tableId, int tableMiss) {
+ return new StringBuffer().append(FLOWID_PREFIX).append(dpnId).append(NwConstants.FLOWID_SEPARATOR)
+ .append(tableId).append(NwConstants.FLOWID_SEPARATOR).append(tableMiss)
+ .append(FLOWID_PREFIX).toString();
+ }
}
private FibManager fibManager;
private IMdsalApiManager mdsalManager;
private IVpnManager vpnmanager;
+ private FibNodeCapableListener fibNcListener;
@Override
public void onSessionInitiated(ProviderContext session) {
fibManager = new FibManager(dataBroker, nexthopService);
fibManager.setMdsalManager(mdsalManager);
fibManager.setVpnmanager(vpnmanager);
+ fibNcListener = new FibNodeCapableListener(dataBroker, fibManager);
} catch (Exception e) {
LOG.error("Error initializing services", e);
}
public void close() throws Exception {
LOG.info("FibManagerProvider Closed");
fibManager.close();
+ fibNcListener.close();
}
public void setMdsalManager(IMdsalApiManager mdsalManager) {
--- /dev/null
+package org.opendaylight.vpnservice.fibmanager;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.vpnservice.AbstractDataChangeListener;
+import org.opendaylight.vpnservice.mdsalutil.MDSALUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
+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.nodes.NodeKey;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class FibNodeCapableListener extends AbstractDataChangeListener<FlowCapableNode> implements AutoCloseable{
+ private static final Logger LOG = LoggerFactory.getLogger(FibNodeCapableListener.class);
+ private ListenerRegistration<DataChangeListener> listenerRegistration;
+ private FibManager fibManager;
+
+ public FibNodeCapableListener(final DataBroker dataBroker, FibManager fibManager) {
+ super(FlowCapableNode.class);
+ registerListener(dataBroker);
+ this.fibManager = fibManager;
+ }
+
+ private void registerListener(final DataBroker db) {
+ try {
+ listenerRegistration = db.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,
+ getWildCardPath(), FibNodeCapableListener.this, DataChangeScope.ONE);
+ } catch (final Exception e) {
+ LOG.error("FibNodeConnectorListener: DataChange listener registration fail!", e);
+ throw new IllegalStateException("FibNodeConnectorListener: registration Listener failed.", e);
+ }
+ }
+
+ private InstanceIdentifier<FlowCapableNode> getWildCardPath() {
+ return InstanceIdentifier.create(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class);
+ }
+
+ @Override
+ public void close() throws Exception {
+ if (listenerRegistration != null) {
+ try {
+ listenerRegistration.close();
+ } catch (final Exception e) {
+ LOG.error("Error when cleaning up DataChangeListener.", e);
+ }
+ listenerRegistration = null;
+ }
+ LOG.info("FibNodeConnectorListener Closed");
+ }
+
+ @Override
+ protected void add(InstanceIdentifier<FlowCapableNode> identifier, FlowCapableNode node) {
+ LOG.trace("FlowCapableNode Added: key: " + identifier + ", value=" + node );
+ NodeKey nodeKey = identifier.firstKeyOf(Node.class, NodeKey.class);
+ long dpnId = MDSALUtil.getDpnIdFromNodeName(nodeKey.getId());
+ fibManager.processNodeAdd(dpnId);
+ }
+
+ @Override
+ protected void remove(InstanceIdentifier<FlowCapableNode> identifier, FlowCapableNode del) {
+ }
+
+ @Override
+ protected void update(InstanceIdentifier<FlowCapableNode> identifier, FlowCapableNode original, FlowCapableNode update) {
+ }
+}