+ Preconditions.checkNotNull(sff, "Input service function forwarder cannot be NULL!");
+ Preconditions.checkNotNull(acl, "Input accesslist cannot be NULL!");
+
+ // Validate if any service function forwarder exists by the name, using SFC provider APIs.
+ ServiceFunctionForwarder serviceForwarder =
+ SfcProviderServiceForwarderAPI.readServiceFunctionForwarder(sff.getName());
+ if (serviceForwarder == null) {
+ LOG.debug("Service Function Forwarder = {} not yet configured. Skip processing !!", sff.getName());
+ return;
+ }
+
+ // If a service function forwarder exists, then get the corresponding OVS Bridge details and Openflow NodeId.
+ // If OVS Bridge augmentation is configured, the following API returns NULL.
+ String datapathId = SfcOvsUtil.getOpenFlowNodeIdForSff(serviceForwarder);
+ if (datapathId == null) {
+ LOG.debug("Service Function Forwarder = {} is not augemented with "
+ + "OVS Bridge Information. Skip processing!!", sff.getName());
+ }
+ // If openflow Node Id is NULL, get all the bridge nodes using southbound apis and fetch
+ // SFF with matching name. From this bridge name, get the openflow data path ID.
+ if (datapathId == null) {
+ Node node = null;
+ final List<Node> nodes = nodeCacheManager.getBridgeNodes();
+ if (nodes.isEmpty()) {
+ LOG.debug("Noop with Classifier Creation on SFF={}. No Bridges configured YET!!", sff.getName());
+ } else {
+ for (Node dstNode : nodes) {
+ LOG.debug("Processing Node={}, sff={}", dstNode.getNodeId().getValue(), sff.getName());
+ if (dstNode.getNodeId().getValue().equalsIgnoreCase(sff.getName())) {
+ LOG.debug("Found matching OVSDB Bridge Name!!= {}", dstNode.getNodeId().getValue());
+ node = dstNode;
+ break;
+ }
+ }
+ }
+ }
+
+ LOG.debug("Processing the Classifier rules on Node={}", datapathId);
+ if (datapathId != null) {
+ // Program the OF flow on the corresponding open flow node.
+ Iterator<AccessListEntry> itr = acl.getAccessListEntries().getAccessListEntry().iterator();
+ while (itr.hasNext()) {
+ AccessListEntry entry = itr.next();
+ programOFRules(entry, datapathId, true);
+ }
+ }
+ }
+
+ private void programOFRules(AccessListEntry entry, String datapathId, boolean write) {
+ NodeBuilder nodeBuilder = new NodeBuilder();
+ nodeBuilder.setId(new NodeId(Constants.OPENFLOW_NODE_PREFIX + datapathId));
+ nodeBuilder.setKey(new NodeKey(nodeBuilder.getId()));
+
+ //Create the match using match builder, by parsing the Accesslist Entry Match.
+ MatchBuilder matchBuilder = null;
+ matchBuilder = buildMatch(entry.getRuleName(), entry.getMatches(), datapathId);
+
+ InstructionsBuilder isb = null;
+ isb = buildActions(entry.getRuleName(), entry.getActions(), datapathId);
+
+ String flowId = "NETVIRT_SFC_FLOW" + "_" + entry.getRuleName();
+
+ FlowBuilder flowBuilder = new FlowBuilder();
+ flowBuilder.setId(new FlowId(flowId));
+ FlowKey key = new FlowKey(new FlowId(flowId));
+ flowBuilder.setMatch(matchBuilder.build());
+ flowBuilder.setPriority(DEFAULT_FLOW_PRIORITY);
+ flowBuilder.setBarrier(true);
+ flowBuilder.setTableId(this.getTable());
+ flowBuilder.setKey(key);
+ flowBuilder.setFlowName(flowId);
+ flowBuilder.setHardTimeout(0);
+ flowBuilder.setIdleTimeout(0);
+
+ flowBuilder.setInstructions(isb.build());
+
+ if (write) {
+ writeFlow(flowBuilder, nodeBuilder);
+ } else {
+ removeFlow(flowBuilder, nodeBuilder);
+ }
+ }
+
+ private InstructionsBuilder buildActions(String ruleName, Actions actions, String datapathId) {
+ InstructionBuilder ib = new InstructionBuilder();
+
+ if (actions.getPacketHandling() instanceof Deny) {
+ InstructionUtils.createDropInstructions(ib);
+ } else if (actions.getPacketHandling() instanceof Permit) {
+ //Permit actPermit = (Permit) actions.getPacketHandling();
+ } else {
+ InstructionUtils.createDropInstructions(ib);
+ }
+
+ ib.setOrder(0);
+ ib.setKey(new InstructionKey(0));
+ // Instructions List Stores Individual Instructions
+ List<Instruction> instructions = Lists.newArrayList();
+ instructions.add(ib.build());
+
+ // Call the InstructionBuilder Methods Containing Actions
+ ib = this.getMutablePipelineInstructionBuilder();
+ ib.setOrder(1);
+ ib.setKey(new InstructionKey(1));
+ instructions.add(ib.build());