OpenflowClassifierProcessor { public List<FlowDetails> processClassifier( final SclServiceFunctionForwarder theClassifier, final Acl theAcl, final boolean addClassifierScenario) { addClassifier = addClassifierScenario; Optional<ServiceFunctionForwarder> sff = Optional.of(new SffName(theClassifier.getName())) .map(SfcProviderServiceForwarderAPI::readServiceFunctionForwarder); Optional<String> itfName = classifierHandler.getInterfaceNameFromClassifier(theClassifier); if (!sff.isPresent() || !itfName.isPresent()) { LOG.error("createdServiceFunctionClassifier: " + "Cannot install ACL rules in classifier. SFF exists? {}; Interface exists? {}", sff.isPresent(), itfName.isPresent()); return Collections.emptyList(); } classifierInterface = classifierHandler.usesLogicalInterfaces(sff.get()) ? logicallyAttachedClassifier : bareClassifier.setSff(sff.get()); Optional<String> nodeName = itfName.flatMap(classifierInterface::getNodeName); if(!nodeName.isPresent()) { LOG.error("createdServiceFunctionClassifier: Could not extract the node name from the OVS interface"); return Collections.emptyList(); } if (classifierHandler.usesLogicalInterfaces(sff.get())) { if (addClassifierScenario) { ClassifierGeniusIntegration.performGeniusServiceBinding(tx, itfName.get()); LOG.info("processClassifier - Bound interface {}", itfName.get()); } else { ClassifierGeniusIntegration.performGeniusServiceUnbinding(tx, itfName.get()); LOG.info("processClassifier - Unbound interface {}", itfName.get()); } } return theAcl .getAccessListEntries() .getAce() .stream() .map(theAce -> processAce(nodeName.get(), sff.get(), theClassifier.getName(), theAcl.getAclName(), itfName.get(), theAce)) .reduce(new ArrayList<>(), (dstList, theList) -> Stream.concat(dstList.stream(), theList.stream()).collect(Collectors.toList())); } private  OpenflowClassifierProcessor();  OpenflowClassifierProcessor(WriteTransaction theTx,
                                       LogicallyAttachedClassifier theLogicClassifier,
                                       BareClassifier theBareClassifier); List<FlowDetails> processClassifierList(Acl theAcl,
                                                   boolean addClassifier,
                                                   List<SclServiceFunctionForwarder> classifierList); List<FlowDetails> processClassifier(
            final SclServiceFunctionForwarder theClassifier,
            final Acl theAcl,
            final boolean addClassifierScenario); @Subscribe void refreshTransaction(WriteTransaction theTx);  }
@Test public void addClassifierDpdkScenario() { when(sff.getSffDataPlaneLocator()).thenReturn(new ArrayList<>()); PowerMockito.when(SfcOvsUtil.getDpdkOfPort(anyString(), anyString())).thenReturn(3L); BareClassifier bareClassifierHandler = Mockito.spy(new BareClassifier(sff)); doReturn(Optional.of(FIRST_SF_NODE_NAME)).when(bareClassifierHandler).getNodeName(anyString()); OpenflowClassifierProcessor classifierManager = new OpenflowClassifierProcessor(readWriteTransaction, new LogicallyAttachedClassifier(dataGetter), bareClassifierHandler); List<FlowDetails> theFlows = classifierManager.processClassifier(sffClassifier, acl, true); Assert.assertFalse(theFlows.isEmpty()); Assert.assertEquals(2 + 2 + 1, theFlows.size()); }
@Test public void addClassifierEmptyAcl() { OpenflowClassifierProcessor classifierManager = new OpenflowClassifierProcessor(readWriteTransaction, classifierInterface, new BareClassifier()); when(accessListEntries.getAce()).thenReturn(new ArrayList<>()); List<FlowDetails> theFlows = classifierManager.processClassifier(sffClassifier, acl, true); Assert.assertTrue(theFlows.isEmpty()); }
@Test public void addClassifierEmptyClassifier() { OpenflowClassifierProcessor classifierManager = new OpenflowClassifierProcessor(readWriteTransaction, new LogicallyAttachedClassifier(dataGetter), new BareClassifier()); PowerMockito.when(SfcProviderServiceForwarderAPI.readServiceFunctionForwarder(any(SffName.class))) .thenReturn(null); List<FlowDetails> theFlows = classifierManager.processClassifier(sffClassifier, acl, true); Assert.assertTrue(theFlows.isEmpty()); }
@Test public void removeClassifierOK() { when(dataGetter.getFirstHopDataplaneId(any(RenderedServicePath.class))) .thenReturn(Optional.of(FIRST_SF_DATAPLANE_ID)); LogicallyAttachedClassifier classifierInterface = Mockito.spy(new LogicallyAttachedClassifier(dataGetter)); doReturn(Optional.of(FIRST_SF_NODE_NAME)).when(classifierInterface).getNodeName(anyString()); OpenflowClassifierProcessor classifierManager = new OpenflowClassifierProcessor(readWriteTransaction, classifierInterface, new BareClassifier()); List<FlowDetails> theFlows = classifierManager.processClassifier(sffClassifier, acl, false); Assert.assertFalse(theFlows.isEmpty()); theFlows.forEach(flow -> LOG.info("The flow: {}", flow.getFlow())); Assert.assertEquals(1, theFlows.size()); }
@Test public void removeClassifierLegacyScenario() { when(sff.getSffDataPlaneLocator()).thenReturn(new ArrayList<>()); PowerMockito.when(SfcOvsUtil.getDpdkOfPort(anyString(), anyString())).thenReturn(null); BareClassifier classifierInterface = Mockito.spy(new BareClassifier(sff)); doReturn(Optional.of(FIRST_SF_NODE_NAME)).when(classifierInterface).getNodeName(anyString()); OpenflowClassifierProcessor classifierManager = new OpenflowClassifierProcessor(readWriteTransaction, new LogicallyAttachedClassifier(dataGetter), classifierInterface); List<FlowDetails> theFlows = classifierManager.processClassifier(sffClassifier, acl, false); Assert.assertFalse(theFlows.isEmpty()); Assert.assertEquals(1 + 1, theFlows.size()); }
@Test public void removeClassifierDpdkScenario() { when(sff.getSffDataPlaneLocator()).thenReturn(new ArrayList<>()); PowerMockito.when(SfcOvsUtil.getDpdkOfPort(anyString(), anyString())).thenReturn(null); BareClassifier classifierInterface = Mockito.spy(new BareClassifier(sff)); doReturn(Optional.of(FIRST_SF_NODE_NAME)).when(classifierInterface).getNodeName(anyString()); OpenflowClassifierProcessor classifierManager = new OpenflowClassifierProcessor(readWriteTransaction, new LogicallyAttachedClassifier(dataGetter), classifierInterface); List<FlowDetails> theFlows = classifierManager.processClassifier(sffClassifier, acl, false); Assert.assertFalse(theFlows.isEmpty()); Assert.assertEquals(1 + 1, theFlows.size()); }
@Test public void removeClassifierEmptyAcl() { OpenflowClassifierProcessor classifierManager = new OpenflowClassifierProcessor(readWriteTransaction, classifierInterface, new BareClassifier()); when(accessListEntries.getAce()).thenReturn(new ArrayList<>()); List<FlowDetails> theFlows = classifierManager.processClassifier(sffClassifier, acl, false); Assert.assertTrue(theFlows.isEmpty()); }
@Test public void removeClassifierEmptyClassifier() { OpenflowClassifierProcessor classifierManager = new OpenflowClassifierProcessor(readWriteTransaction, new LogicallyAttachedClassifier(dataGetter), new BareClassifier()); PowerMockito.when(SfcProviderServiceForwarderAPI.readServiceFunctionForwarder(any(SffName.class))) .thenReturn(null); List<FlowDetails> theFlows = classifierManager.processClassifier(sffClassifier, acl, false); Assert.assertTrue(theFlows.isEmpty()); }
@Test public void addClassifierOK() { when(dataGetter.getFirstHopDataplaneId(any(RenderedServicePath.class))) .thenReturn(Optional.of(FIRST_SF_DATAPLANE_ID)); LogicallyAttachedClassifier classifierInterface = Mockito.spy(new LogicallyAttachedClassifier(dataGetter)); doReturn(Optional.of(FIRST_SF_NODE_NAME)).when(classifierInterface).getNodeName(anyString()); OpenflowClassifierProcessor classifierManager = new OpenflowClassifierProcessor(readWriteTransaction, classifierInterface, new BareClassifier()); PowerMockito.when(SfcOvsUtil.getDpdkOfPort(anyString(), anyString())).thenReturn(null); List<FlowDetails> theFlows = classifierManager.processClassifier(sffClassifier, acl, true); Assert.assertFalse(theFlows.isEmpty()); Assert.assertEquals(2, theFlows.size()); }
@Test public void addClassifierLegacyScenario() { when(sff.getSffDataPlaneLocator()).thenReturn(new ArrayList<>()); PowerMockito.when(SfcOvsUtil.getDpdkOfPort(anyString(), anyString())).thenReturn(null); BareClassifier bareClassifierHandler = Mockito.spy(new BareClassifier(sff)); LogicallyAttachedClassifier logicallyAttachedClassifierHandler = new LogicallyAttachedClassifier(dataGetter); doReturn(Optional.of(FIRST_SF_NODE_NAME)).when(bareClassifierHandler).getNodeName(anyString()); OpenflowClassifierProcessor classifierManager = new OpenflowClassifierProcessor(readWriteTransaction, logicallyAttachedClassifierHandler, bareClassifierHandler); List<FlowDetails> theFlows = classifierManager.processClassifier(sffClassifier, acl, true); Assert.assertFalse(theFlows.isEmpty()); Assert.assertEquals(2 + 1, theFlows.size()); }