import org.opendaylight.openflowplugin.openflow.md.core.session.SessionManager;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRemoved;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRemovedBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeUpdated;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeUpdatedBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
GetFeaturesOutput features = context.getFeatures();
BigInteger datapathId = features.getDatapathId();
InstanceIdentifier<Node> identifier = identifierFromDatapathId(datapathId);
-
+ NodeRef nodeRef = new NodeRef(identifier);
NodeId nodeId = nodeIdFromDatapathId(datapathId);
ModelDrivenSwitchImpl ofSwitch = new ModelDrivenSwitchImpl(nodeId, identifier, context);
salSwitches.put(identifier, ofSwitch);
LOG.info("ModelDrivenSwitch for {} registered to MD-SAL.", datapathId.toString());
- publishService.publish(nodeAdded(ofSwitch, features));
+ publishService.publish(nodeAdded(ofSwitch, features,nodeRef));
}
- private NodeUpdated nodeAdded(ModelDrivenSwitch sw, GetFeaturesOutput features) {
+ @Override
+ public void onSessionRemoved(SessionContext context) {
+ GetFeaturesOutput features = context.getFeatures();
+ BigInteger datapathId = features.getDatapathId();
+ InstanceIdentifier<Node> identifier = identifierFromDatapathId(datapathId);
+ NodeRef nodeRef = new NodeRef(identifier);
+ NodeRemoved nodeRemoved = nodeRemoved(nodeRef);
+
+ LOG.info("ModelDrivenSwitch for {} unregistred from MD-SAL.", datapathId.toString());
+ publishService.publish(nodeRemoved);
+ }
+
+ private NodeUpdated nodeAdded(ModelDrivenSwitch sw, GetFeaturesOutput features, NodeRef nodeRef) {
NodeUpdatedBuilder builder = new NodeUpdatedBuilder();
builder.setId(sw.getNodeId());
- builder.setNodeRef(new NodeRef(InstanceIdentifier.builder()
- .node(Nodes.class)
- .node(Node.class, new NodeKey(builder.getId()))
- .toInstance()));
+ builder.setNodeRef(nodeRef);
+ return builder.build();
+ }
+
+ private NodeRemoved nodeRemoved(NodeRef nodeRef) {
+ NodeRemovedBuilder builder = new NodeRemovedBuilder();
+ builder.setNodeRef(nodeRef);
return builder.build();
}
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
-import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
import org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductor;
import org.opendaylight.openflowplugin.openflow.md.core.IMDMessageListener;
import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
}
context.getPrimaryConductor().disconnect();
context.setValid(false);
- sessionLot.remove(sessionKey);
+ removeSessionContext(context);
// TODO:: notify listeners
}
}
invalidateAuxiliary(sessionContext, auxEntry.getKey(), true);
}
sessionContext.setValid(false);
- sessionLot.remove(sessionContext.getSessionKey(), sessionContext);
+ removeSessionContext(sessionContext);
// TODO:: notify listeners
}
}
+ private void removeSessionContext(SessionContext sessionContext) {
+ sessionLot.remove(sessionContext.getSessionKey(), sessionContext);
+ sessionNotifier.onSessionRemoved(sessionContext);
+ }
+
@Override
public void addSessionContext(SwitchConnectionDistinguisher sessionKey, SessionContext context) {
sessionLot.put(sessionKey, context);
}
}
}
+
+ public void onSessionRemoved(SessionContext context) {
+ for (ListenerRegistration<SessionListener> listener : sessionListeners) {
+ try {
+ listener.getInstance().onSessionRemoved(context);
+ } catch (Exception e) {
+ LOG.error("Unhandled exeption occured while invoking onSessionRemoved on listener", e);
+ }
+ }
+ }
};
@Override