@Test public void onDataChange_Valid() throws Exception { InstanceIdentifier<Node> instanceId = InstanceIdentifier.builder(Nodes.class) .child(Node.class, new NodeKey(new NodeId("openflow:1"))) .build(); Node topoNode = new NodeBuilder().setId(new NodeId("openflow:1")).build(); DataTreeModification<Node> mockChange = Mockito.mock(DataTreeModification.class); DataObjectModification<Node> mockModification = Mockito.mock(DataObjectModification.class); when(mockModification.getDataAfter()).thenReturn(topoNode); when(mockModification.getModificationType()).thenReturn(DataObjectModification.ModificationType.WRITE); when(mockChange.getRootPath()).thenReturn(new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, instanceId)); when(mockChange.getRootNode()).thenReturn(mockModification); initialFlowWriter.onDataTreeChanged(Collections.singletonList(mockChange)); Thread.sleep(250); verify(salFlowService, times(1)).addFlow(any(AddFlowInput.class)); }
@Override public void onDataTreeChanged(Collection<DataTreeModification<Node>> changes) { Set<InstanceIdentifier<?>> nodeIds = new HashSet<>(); for (DataTreeModification<Node> change: changes) { DataObjectModification<Node> rootNode = change.getRootNode(); final InstanceIdentifier<Node> identifier = change.getRootPath().getRootIdentifier(); switch (rootNode.getModificationType()) { case WRITE: if (rootNode.getDataBefore() == null) { nodeIds.add(identifier); } break; default: break; } } if (!nodeIds.isEmpty()) { initialFlowExecutor.execute(new InitialFlowWriterProcessor(nodeIds)); } }
InitialFlowWriter implements DataTreeChangeListener<Node> { @Override public void onDataTreeChanged(Collection<DataTreeModification<Node>> changes) { Set<InstanceIdentifier<?>> nodeIds = new HashSet<>(); for (DataTreeModification<Node> change: changes) { DataObjectModification<Node> rootNode = change.getRootNode(); final InstanceIdentifier<Node> identifier = change.getRootPath().getRootIdentifier(); switch (rootNode.getModificationType()) { case WRITE: if (rootNode.getDataBefore() == null) { nodeIds.add(identifier); } break; default: break; } } if (!nodeIds.isEmpty()) { initialFlowExecutor.execute(new InitialFlowWriterProcessor(nodeIds)); } } }
InitialFlowWriter implements DataTreeChangeListener<Node> { @Override public void onDataTreeChanged(Collection<DataTreeModification<Node>> changes) { Set<InstanceIdentifier<?>> nodeIds = new HashSet<>(); for (DataTreeModification<Node> change: changes) { DataObjectModification<Node> rootNode = change.getRootNode(); final InstanceIdentifier<Node> identifier = change.getRootPath().getRootIdentifier(); switch (rootNode.getModificationType()) { case WRITE: if (rootNode.getDataBefore() == null) { nodeIds.add(identifier); } break; default: break; } } if (!nodeIds.isEmpty()) { initialFlowExecutor.execute(new InitialFlowWriterProcessor(nodeIds)); } } InitialFlowWriter(SalFlowService salFlowService); }
InitialFlowWriter implements DataTreeChangeListener<Node> { @Override public void onDataTreeChanged(Collection<DataTreeModification<Node>> changes) { Set<InstanceIdentifier<?>> nodeIds = new HashSet<>(); for (DataTreeModification<Node> change: changes) { DataObjectModification<Node> rootNode = change.getRootNode(); final InstanceIdentifier<Node> identifier = change.getRootPath().getRootIdentifier(); switch (rootNode.getModificationType()) { case WRITE: if (rootNode.getDataBefore() == null) { nodeIds.add(identifier); } break; default: break; } } if (!nodeIds.isEmpty()) { initialFlowExecutor.execute(new InitialFlowWriterProcessor(nodeIds)); } } InitialFlowWriter(SalFlowService salFlowService); void setFlowTableId(short flowTableId); void setFlowPriority(int flowPriority); void setFlowIdleTimeout(int flowIdleTimeout); void setFlowHardTimeout(int flowHardTimeout); void setIsHybridMode(boolean isHybridMode); ListenerRegistration<InitialFlowWriter> registerAsDataChangeListener(DataBroker dataBroker); @Override void onDataTreeChanged(Collection<DataTreeModification<Node>> changes); }
InitialFlowWriter implements DataTreeChangeListener<Node> { @Override public void onDataTreeChanged(Collection<DataTreeModification<Node>> changes) { Set<InstanceIdentifier<?>> nodeIds = new HashSet<>(); for (DataTreeModification<Node> change: changes) { DataObjectModification<Node> rootNode = change.getRootNode(); final InstanceIdentifier<Node> identifier = change.getRootPath().getRootIdentifier(); switch (rootNode.getModificationType()) { case WRITE: if (rootNode.getDataBefore() == null) { nodeIds.add(identifier); } break; default: break; } } if (!nodeIds.isEmpty()) { initialFlowExecutor.execute(new InitialFlowWriterProcessor(nodeIds)); } } InitialFlowWriter(SalFlowService salFlowService); void setFlowTableId(short flowTableId); void setFlowPriority(int flowPriority); void setFlowIdleTimeout(int flowIdleTimeout); void setFlowHardTimeout(int flowHardTimeout); void setIsHybridMode(boolean isHybridMode); ListenerRegistration<InitialFlowWriter> registerAsDataChangeListener(DataBroker dataBroker); @Override void onDataTreeChanged(Collection<DataTreeModification<Node>> changes);  }