AclServiceOFFlowBuilder { public static Map<String,List<MatchInfoBase>> programIcmpFlow(AceIp acl) { List<MatchInfoBase> flowMatches = new ArrayList<>(); flowMatches.addAll(addSrcIpMatches(acl)); flowMatches.addAll(addDstIpMatches(acl)); SourcePortRange sourcePortRange = acl.getSourcePortRange(); String flowId = "ICMP_"; if (sourcePortRange != null) { if (acl.getAceIpVersion() instanceof AceIpv4) { flowMatches.add(new MatchIcmpv4(sourcePortRange.getLowerPort().getValue().shortValue(), sourcePortRange.getUpperPort().getValue().shortValue())); flowId = flowId + "V4_SOURCE_" + sourcePortRange.getLowerPort().getValue() + sourcePortRange.getUpperPort().getValue(); } else if (acl.getAceIpVersion() instanceof AceIpv6) { flowMatches.add(new MatchIcmpv6(sourcePortRange.getLowerPort().getValue().shortValue(), sourcePortRange.getUpperPort().getValue().shortValue())); flowId = flowId + "V6_SOURCE_" + sourcePortRange.getLowerPort().getValue() + "_" + sourcePortRange.getUpperPort().getValue() + "_"; } } DestinationPortRange destinationPortRange = acl.getDestinationPortRange(); if (destinationPortRange != null) { if (acl.getAceIpVersion() instanceof AceIpv4) { flowMatches.add(new MatchIcmpv4(destinationPortRange.getLowerPort().getValue().shortValue(), destinationPortRange.getUpperPort().getValue().shortValue())); flowId = flowId + "V4_DESTINATION_" + destinationPortRange.getLowerPort().getValue() + destinationPortRange.getUpperPort().getValue() + "_"; } else if (acl.getAceIpVersion() instanceof AceIpv6) { flowMatches.add(new MatchIcmpv6(destinationPortRange.getLowerPort().getValue().shortValue(), destinationPortRange.getUpperPort().getValue().shortValue())); flowId = flowId + "V6_DESTINATION_" + destinationPortRange.getLowerPort().getValue() + destinationPortRange.getUpperPort().getValue() + "_"; } } if (acl.getAceIpVersion() instanceof AceIpv6 && acl.getProtocol().toJava() == NwConstants.IP_PROT_ICMP) { flowMatches.add(new MatchIpProtocol(AclConstants.IP_PROT_ICMPV6)); } else { flowMatches.add(new MatchIpProtocol(acl.getProtocol().toJava())); } Map<String,List<MatchInfoBase>> flowMatchesMap = new HashMap<>(); flowMatchesMap.put(flowId,flowMatches); return flowMatchesMap; } private  AclServiceOFFlowBuilder(); @Nullable static Map<String, List<MatchInfoBase>> programIpFlow(Matches matches); static Map<String,List<MatchInfoBase>> programEtherFlow(AceIp acl); static Map<String,List<MatchInfoBase>> programOtherProtocolFlow(AceIp acl); static Map<String,List<MatchInfoBase>> programIcmpFlow(AceIp acl); static Map<String,List<MatchInfoBase>> programTcpFlow(AceIp acl); static Map<String,List<MatchInfoBase>> programUdpFlow(AceIp acl); static List<MatchInfoBase> addSrcIpMatches(AceIp acl); static List<MatchInfoBase> addDstIpMatches(AceIp acl); static List<MatchInfoBase> addLPortTagMatches(int lportTag, int conntrackState, int conntrackMask,
            Class<? extends ServiceModeBase> serviceMode); static List<InstructionInfo> getDropInstructionInfo(); static List<InstructionInfo> getResubmitInstructionInfo(short tableId); static List<InstructionInfo> getGotoInstructionInfo(short gotoTableId); static Map<Integer,Integer> getLayer4MaskForRange(int portMin, int portMax);  }
@Test public void testprogramIcmpFlow() { AceIpBuilder builder = AclServiceTestUtils.prepareAceIpBuilder("10.1.1.1/24", "20.1.1.1/24", "1024", "2048", (short) 1); Map<String, List<MatchInfoBase>> flowMatchesMap = AclServiceOFFlowBuilder.programIcmpFlow(builder.build()); List<MatchInfoBase> flowMatches = flowMatchesMap.entrySet().iterator().next().getValue(); AclServiceTestUtils.verifyGeneralFlows(flowMatches, "1", "10.1.1.1", "20.1.1.1", "24"); int matches = 0; MatchIcmpv4 check = new MatchIcmpv4((short) 1024, (short) 2048); for (MatchInfoBase flowMatch : flowMatches) { if (check.equals(flowMatch)) { matches++; } } assertEquals(2, matches); }