use of org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey in project openflowplugin by opendaylight.
the class OF10DeviceInitializerTest method setUp.
@Before
public void setUp() throws Exception {
final KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier = DeviceStateUtil.createNodeInstanceIdentifier(new NodeId("openflow:1"));
deviceInitializer = new OF10DeviceInitializer();
when(featuresReply.getCapabilitiesV10()).thenReturn(capabilitiesV10);
when(featuresReply.getPhyPort()).thenReturn(Collections.singletonList(new PhyPortBuilder().setPortNo(42L).build()));
when(connectionContext.getFeatures()).thenReturn(featuresReply);
when(connectionContext.getOutboundQueueProvider()).thenReturn(outboundQueueProvider);
when(deviceContext.getDeviceState()).thenReturn(deviceState);
when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodeInstanceIdentifier);
when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo);
when(deviceContext.getMessageSpy()).thenReturn(messageSpy);
when(translatorLibrary.lookupTranslator(any())).thenReturn(messageTranslator);
when(deviceContext.oook()).thenReturn(translatorLibrary);
when(requestContext.getXid()).thenReturn(new Xid(42L));
when(requestContext.getFuture()).thenReturn(RpcResultBuilder.success().buildFuture());
when(deviceContext.createRequestContext()).thenReturn(requestContext);
when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey in project openflowplugin by opendaylight.
the class TerminationPointChangeListenerImplTest method testOnNodeConnectorRemoved.
@SuppressWarnings("rawtypes")
@Test
public void testOnNodeConnectorRemoved() {
NodeKey topoNodeKey = new NodeKey(new NodeId("node1"));
TerminationPointKey terminationPointKey = new TerminationPointKey(new TpId("tp1"));
final InstanceIdentifier<Node> topoNodeII = topologyIID.child(Node.class, topoNodeKey);
Node topoNode = new NodeBuilder().setKey(topoNodeKey).build();
org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey nodeKey = newInvNodeKey(topoNodeKey.getNodeId().getValue());
org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey ncKey = newInvNodeConnKey(terminationPointKey.getTpId().getValue());
final InstanceIdentifier<?> invNodeConnID = newNodeConnID(nodeKey, ncKey);
List<Link> linkList = Arrays.asList(newLink("link1", newSourceTp("tp1"), newDestTp("dest")), newLink("link2", newSourceTp("source"), newDestTp("tp1")), newLink("link3", newSourceTp("source2"), newDestTp("dest2")));
final Topology topology = new TopologyBuilder().setLink(linkList).build();
final InstanceIdentifier[] expDeletedIIDs = { topologyIID.child(Link.class, linkList.get(0).getKey()), topologyIID.child(Link.class, linkList.get(1).getKey()), topologyIID.child(Node.class, new NodeKey(new NodeId("node1"))).child(TerminationPoint.class, new TerminationPointKey(new TpId("tp1"))) };
final SettableFuture<Optional<Topology>> readFuture = SettableFuture.create();
readFuture.set(Optional.of(topology));
ReadWriteTransaction mockTx1 = mock(ReadWriteTransaction.class);
doReturn(Futures.makeChecked(readFuture, ReadFailedException.MAPPER)).when(mockTx1).read(LogicalDatastoreType.OPERATIONAL, topologyIID);
SettableFuture<Optional<Node>> readFutureNode = SettableFuture.create();
readFutureNode.set(Optional.of(topoNode));
doReturn(Futures.makeChecked(readFutureNode, ReadFailedException.MAPPER)).when(mockTx1).read(LogicalDatastoreType.OPERATIONAL, topoNodeII);
final CountDownLatch submitLatch1 = setupStubbedSubmit(mockTx1);
int expDeleteCalls = expDeletedIIDs.length;
CountDownLatch deleteLatch = new CountDownLatch(expDeleteCalls);
ArgumentCaptor<InstanceIdentifier> deletedLinkIDs = ArgumentCaptor.forClass(InstanceIdentifier.class);
setupStubbedDeletes(mockTx1, deletedLinkIDs, deleteLatch);
doReturn(mockTx1).when(mockTxChain).newReadWriteTransaction();
DataTreeModification dataTreeModification = setupDataTreeChange(DELETE, invNodeConnID);
terminationPointListener.onDataTreeChanged(Collections.singleton(dataTreeModification));
waitForSubmit(submitLatch1);
setReadFutureAsync(topology, readFuture);
waitForDeletes(expDeleteCalls, deleteLatch);
assertDeletedIDs(expDeletedIIDs, deletedLinkIDs);
verifyMockTx(mockTx1);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey in project openflowplugin by opendaylight.
the class TerminationPointChangeListenerImplTest method testOnNodeConnectorUpdatedWithPortDown.
@SuppressWarnings("rawtypes")
@Test
public void testOnNodeConnectorUpdatedWithPortDown() {
org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey nodeKey = newInvNodeKey("node1");
org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey ncKey = newInvNodeConnKey("tp1");
final InstanceIdentifier<?> invNodeConnID = newNodeConnID(nodeKey, ncKey);
List<Link> linkList = Arrays.asList(newLink("link1", newSourceTp("tp1"), newDestTp("dest")));
Topology topology = new TopologyBuilder().setLink(linkList).build();
ReadWriteTransaction mockTx = mock(ReadWriteTransaction.class);
doReturn(Futures.immediateCheckedFuture(Optional.of(topology))).when(mockTx).read(LogicalDatastoreType.OPERATIONAL, topologyIID);
setupStubbedSubmit(mockTx);
CountDownLatch deleteLatch = new CountDownLatch(1);
ArgumentCaptor<InstanceIdentifier> deletedLinkIDs = ArgumentCaptor.forClass(InstanceIdentifier.class);
setupStubbedDeletes(mockTx, deletedLinkIDs, deleteLatch);
doReturn(mockTx).when(mockTxChain).newReadWriteTransaction();
DataTreeModification dataTreeModification = setupDataTreeChange(WRITE, invNodeConnID);
when(dataTreeModification.getRootNode().getDataAfter()).thenReturn(provideFlowCapableNodeConnector(false, true));
terminationPointListener.onDataTreeChanged(Collections.singleton(dataTreeModification));
waitForDeletes(1, deleteLatch);
InstanceIdentifier<TerminationPoint> expTpPath = topologyIID.child(Node.class, new NodeKey(new NodeId("node1"))).child(TerminationPoint.class, new TerminationPointKey(new TpId("tp1")));
verify(mockTx).merge(eq(LogicalDatastoreType.OPERATIONAL), eq(expTpPath), any(TerminationPoint.class), eq(true));
assertDeletedIDs(new InstanceIdentifier[] { topologyIID.child(Link.class, linkList.get(0).getKey()) }, deletedLinkIDs);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey in project openflowplugin by opendaylight.
the class TerminationPointChangeListenerImplTest method testOnNodeConnectorUpdated.
@Test
public void testOnNodeConnectorUpdated() {
org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey nodeKey = newInvNodeKey("node1");
org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey ncKey = newInvNodeConnKey("tp1");
InstanceIdentifier<?> invNodeConnID = newNodeConnID(nodeKey, ncKey);
ReadWriteTransaction mockTx = mock(ReadWriteTransaction.class);
CountDownLatch submitLatch = setupStubbedSubmit(mockTx);
doReturn(mockTx).when(mockTxChain).newReadWriteTransaction();
DataTreeModification dataTreeModification = setupDataTreeChange(WRITE, invNodeConnID);
terminationPointListener.onDataTreeChanged(Collections.singleton(dataTreeModification));
waitForSubmit(submitLatch);
ArgumentCaptor<TerminationPoint> mergedNode = ArgumentCaptor.forClass(TerminationPoint.class);
NodeId expNodeId = new NodeId("node1");
TpId expTpId = new TpId("tp1");
InstanceIdentifier<TerminationPoint> expTpPath = topologyIID.child(Node.class, new NodeKey(expNodeId)).child(TerminationPoint.class, new TerminationPointKey(expTpId));
verify(mockTx).merge(eq(LogicalDatastoreType.OPERATIONAL), eq(expTpPath), mergedNode.capture(), eq(true));
assertEquals("getTpId", expTpId, mergedNode.getValue().getTpId());
InventoryNodeConnector augmentation = mergedNode.getValue().getAugmentation(InventoryNodeConnector.class);
assertNotNull("Missing augmentation", augmentation);
assertEquals("getInventoryNodeConnectorRef", new NodeConnectorRef(invNodeConnID), augmentation.getInventoryNodeConnectorRef());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey in project openflowplugin by opendaylight.
the class LLDPDiscoveryUtils method lldpToNodeConnectorRef.
/**
* Returns the encoded in custom TLV for the given lldp.
*
* @param payload lldp payload
* @param useExtraAuthenticatorCheck make it more secure (CVE-2015-1611 CVE-2015-1612)
* @return nodeConnectorId - encoded in custom TLV of given lldp
*/
@SuppressWarnings("checkstyle:IllegalCatch")
public static NodeConnectorRef lldpToNodeConnectorRef(byte[] payload, boolean useExtraAuthenticatorCheck) {
NodeConnectorRef nodeConnectorRef = null;
if (isLLDP(payload)) {
Ethernet ethPkt = new Ethernet();
try {
ethPkt.deserialize(payload, 0, payload.length * NetUtils.NUM_BITS_IN_A_BYTE);
} catch (PacketException e) {
LOG.warn("Failed to decode LLDP packet {}", e);
return nodeConnectorRef;
}
LLDP lldp = (LLDP) ethPkt.getPayload();
try {
NodeId srcNodeId = null;
NodeConnectorId srcNodeConnectorId = null;
final LLDPTLV systemIdTLV = lldp.getSystemNameId();
if (systemIdTLV != null) {
String srcNodeIdString = new String(systemIdTLV.getValue(), Charset.defaultCharset());
srcNodeId = new NodeId(srcNodeIdString);
} else {
throw new Exception("Node id wasn't specified via systemNameId in LLDP packet.");
}
final LLDPTLV nodeConnectorIdLldptlv = lldp.getCustomTLV(LLDPTLV.createPortSubTypeCustomTLVKey());
if (nodeConnectorIdLldptlv != null) {
srcNodeConnectorId = new NodeConnectorId(LLDPTLV.getCustomString(nodeConnectorIdLldptlv.getValue(), nodeConnectorIdLldptlv.getLength()));
} else {
throw new Exception("Node connector wasn't specified via Custom TLV in LLDP packet.");
}
if (useExtraAuthenticatorCheck) {
boolean secure = checkExtraAuthenticator(lldp, srcNodeConnectorId);
if (!secure) {
LOG.warn("SECURITY ALERT: there is probably a LLDP spoofing attack in progress.");
throw new Exception("Attack. LLDP packet with inconsistent extra authenticator field was received.");
}
}
InstanceIdentifier<NodeConnector> srcInstanceId = InstanceIdentifier.builder(Nodes.class).child(Node.class, new NodeKey(srcNodeId)).child(NodeConnector.class, new NodeConnectorKey(srcNodeConnectorId)).toInstance();
nodeConnectorRef = new NodeConnectorRef(srcInstanceId);
} catch (Exception e) {
LOG.debug("Caught exception while parsing out lldp optional and custom fields", e);
}
}
return nodeConnectorRef;
}
Aggregations