@Test public final void testGetClassifierInstance_onlyEthertype() { secRuleBuilder.setEthertype(EthertypeV4.class); ClassifierInstance ci = SecRuleEntityDecoder.getClassifierInstance(secRuleBuilder.build()); Assert.assertEquals(EtherTypeClassifierDefinition.DEFINITION.getId(), ci.getClassifierDefinitionId()); String expectedName = new StringBuilder().append(EtherTypeClassifierDefinition.DEFINITION.getName().getValue()) .append(MappingUtils.NAME_VALUE_DELIMETER) .append(EthertypeV4.class.getSimpleName()) .toString(); Assert.assertEquals(expectedName, ci.getName().getValue()); Assert.assertEquals(expectedName, ci.getName().getValue()); List<ParameterValue> parameterValues = ci.getParameterValue(); Assert.assertNotNull(parameterValues); Assert.assertEquals(1, parameterValues.size()); ParameterValue parameter = parameterValues.get(0); Assert.assertEquals(EtherTypeClassifierDefinition.ETHERTYPE_PARAM, parameter.getName().getValue()); assertClassifierParameterValue(parameter, EtherTypeClassifierDefinition.IPv4_VALUE, null, null); }
public static ClassifierInstance getClassifierInstance(SecurityRule secRule) { ClassifierInstanceBuilder classifierBuilder = new ClassifierInstanceBuilder(); List<ParameterValue> params = new ArrayList<>(); Integer portMin = secRule.getPortRangeMin(); Integer portMax = secRule.getPortRangeMax(); if (portMin != null && portMax != null) { classifierBuilder.setClassifierDefinitionId(L4ClassifierDefinition.DEFINITION.getId()); if (portMin.equals(portMax)) { params.add(new ParameterValueBuilder().setName(new ParameterName(L4ClassifierDefinition.DST_PORT_PARAM)) .setIntValue(portMin.longValue()) .build()); } else { params.add(new ParameterValueBuilder() .setName(new ParameterName(L4ClassifierDefinition.DST_PORT_RANGE_PARAM)) .setRangeValue( new RangeValueBuilder().setMin(portMin.longValue()).setMax(portMax.longValue()).build()) .build()); } } Long protocol = getProtocol(secRule); if (protocol != null) { if (classifierBuilder.getClassifierDefinitionId() == null) { classifierBuilder.setClassifierDefinitionId(IpProtoClassifierDefinition.DEFINITION.getId()); } params.add(new ParameterValueBuilder() .setName(new ParameterName(IpProtoClassifierDefinition.PROTO_PARAM)) .setIntValue(protocol) .build()); } Long ethertype = getEtherType(secRule); if (ethertype != null) { if (classifierBuilder.getClassifierDefinitionId() == null) { classifierBuilder.setClassifierDefinitionId(EtherTypeClassifierDefinition.DEFINITION.getId()); } params.add(new ParameterValueBuilder() .setName(new ParameterName(EtherTypeClassifierDefinition.ETHERTYPE_PARAM)) .setIntValue(ethertype) .build()); } ClassifierName classifierName = SecRuleNameDecoder.getClassifierInstanceName(secRule); return classifierBuilder.setParameterValue(params).setName(new ClassifierName(classifierName)).build(); }
SecRuleEntityDecoder { public static ClassifierInstance getClassifierInstance(SecurityRule secRule) { ClassifierInstanceBuilder classifierBuilder = new ClassifierInstanceBuilder(); List<ParameterValue> params = new ArrayList<>(); Integer portMin = secRule.getPortRangeMin(); Integer portMax = secRule.getPortRangeMax(); if (portMin != null && portMax != null) { classifierBuilder.setClassifierDefinitionId(L4ClassifierDefinition.DEFINITION.getId()); if (portMin.equals(portMax)) { params.add(new ParameterValueBuilder().setName(new ParameterName(L4ClassifierDefinition.DST_PORT_PARAM)) .setIntValue(portMin.longValue()) .build()); } else { params.add(new ParameterValueBuilder() .setName(new ParameterName(L4ClassifierDefinition.DST_PORT_RANGE_PARAM)) .setRangeValue( new RangeValueBuilder().setMin(portMin.longValue()).setMax(portMax.longValue()).build()) .build()); } } Long protocol = getProtocol(secRule); if (protocol != null) { if (classifierBuilder.getClassifierDefinitionId() == null) { classifierBuilder.setClassifierDefinitionId(IpProtoClassifierDefinition.DEFINITION.getId()); } params.add(new ParameterValueBuilder() .setName(new ParameterName(IpProtoClassifierDefinition.PROTO_PARAM)) .setIntValue(protocol) .build()); } Long ethertype = getEtherType(secRule); if (ethertype != null) { if (classifierBuilder.getClassifierDefinitionId() == null) { classifierBuilder.setClassifierDefinitionId(EtherTypeClassifierDefinition.DEFINITION.getId()); } params.add(new ParameterValueBuilder() .setName(new ParameterName(EtherTypeClassifierDefinition.ETHERTYPE_PARAM)) .setIntValue(ethertype) .build()); } ClassifierName classifierName = SecRuleNameDecoder.getClassifierInstanceName(secRule); return classifierBuilder.setParameterValue(params).setName(new ClassifierName(classifierName)).build(); } }
SecRuleEntityDecoder { public static ClassifierInstance getClassifierInstance(SecurityRule secRule) { ClassifierInstanceBuilder classifierBuilder = new ClassifierInstanceBuilder(); List<ParameterValue> params = new ArrayList<>(); Integer portMin = secRule.getPortRangeMin(); Integer portMax = secRule.getPortRangeMax(); if (portMin != null && portMax != null) { classifierBuilder.setClassifierDefinitionId(L4ClassifierDefinition.DEFINITION.getId()); if (portMin.equals(portMax)) { params.add(new ParameterValueBuilder().setName(new ParameterName(L4ClassifierDefinition.DST_PORT_PARAM)) .setIntValue(portMin.longValue()) .build()); } else { params.add(new ParameterValueBuilder() .setName(new ParameterName(L4ClassifierDefinition.DST_PORT_RANGE_PARAM)) .setRangeValue( new RangeValueBuilder().setMin(portMin.longValue()).setMax(portMax.longValue()).build()) .build()); } } Long protocol = getProtocol(secRule); if (protocol != null) { if (classifierBuilder.getClassifierDefinitionId() == null) { classifierBuilder.setClassifierDefinitionId(IpProtoClassifierDefinition.DEFINITION.getId()); } params.add(new ParameterValueBuilder() .setName(new ParameterName(IpProtoClassifierDefinition.PROTO_PARAM)) .setIntValue(protocol) .build()); } Long ethertype = getEtherType(secRule); if (ethertype != null) { if (classifierBuilder.getClassifierDefinitionId() == null) { classifierBuilder.setClassifierDefinitionId(EtherTypeClassifierDefinition.DEFINITION.getId()); } params.add(new ParameterValueBuilder() .setName(new ParameterName(EtherTypeClassifierDefinition.ETHERTYPE_PARAM)) .setIntValue(ethertype) .build()); } ClassifierName classifierName = SecRuleNameDecoder.getClassifierInstanceName(secRule); return classifierBuilder.setParameterValue(params).setName(new ClassifierName(classifierName)).build(); } private  SecRuleEntityDecoder(); }
SecRuleEntityDecoder { public static ClassifierInstance getClassifierInstance(SecurityRule secRule) { ClassifierInstanceBuilder classifierBuilder = new ClassifierInstanceBuilder(); List<ParameterValue> params = new ArrayList<>(); Integer portMin = secRule.getPortRangeMin(); Integer portMax = secRule.getPortRangeMax(); if (portMin != null && portMax != null) { classifierBuilder.setClassifierDefinitionId(L4ClassifierDefinition.DEFINITION.getId()); if (portMin.equals(portMax)) { params.add(new ParameterValueBuilder().setName(new ParameterName(L4ClassifierDefinition.DST_PORT_PARAM)) .setIntValue(portMin.longValue()) .build()); } else { params.add(new ParameterValueBuilder() .setName(new ParameterName(L4ClassifierDefinition.DST_PORT_RANGE_PARAM)) .setRangeValue( new RangeValueBuilder().setMin(portMin.longValue()).setMax(portMax.longValue()).build()) .build()); } } Long protocol = getProtocol(secRule); if (protocol != null) { if (classifierBuilder.getClassifierDefinitionId() == null) { classifierBuilder.setClassifierDefinitionId(IpProtoClassifierDefinition.DEFINITION.getId()); } params.add(new ParameterValueBuilder() .setName(new ParameterName(IpProtoClassifierDefinition.PROTO_PARAM)) .setIntValue(protocol) .build()); } Long ethertype = getEtherType(secRule); if (ethertype != null) { if (classifierBuilder.getClassifierDefinitionId() == null) { classifierBuilder.setClassifierDefinitionId(EtherTypeClassifierDefinition.DEFINITION.getId()); } params.add(new ParameterValueBuilder() .setName(new ParameterName(EtherTypeClassifierDefinition.ETHERTYPE_PARAM)) .setIntValue(ethertype) .build()); } ClassifierName classifierName = SecRuleNameDecoder.getClassifierInstanceName(secRule); return classifierBuilder.setParameterValue(params).setName(new ClassifierName(classifierName)).build(); } private  SecRuleEntityDecoder(); static ContractId getContractId(SecurityRule secRule); static ClassifierInstance getClassifierInstance(SecurityRule secRule); static ActionRef createActionRefFromActionChoice(ActionChoice action); static ClassifierRef getClassifierRef(SecurityRule secRule); static Direction getDirection(SecurityRule secRule); static Clause getClause(SecurityRule secRule); static boolean isEtherTypeOfOneWithinTwo(SecurityRule one, SecurityRule two); static boolean isProtocolOfOneWithinTwo(SecurityRule one, SecurityRule two); static boolean isPortsOfOneWithinTwo(SecurityRule one, SecurityRule two); static Long getEtherType(SecurityRule secRule); static Long getProtocol(SecurityRule secRule); }
SecRuleEntityDecoder { public static ClassifierInstance getClassifierInstance(SecurityRule secRule) { ClassifierInstanceBuilder classifierBuilder = new ClassifierInstanceBuilder(); List<ParameterValue> params = new ArrayList<>(); Integer portMin = secRule.getPortRangeMin(); Integer portMax = secRule.getPortRangeMax(); if (portMin != null && portMax != null) { classifierBuilder.setClassifierDefinitionId(L4ClassifierDefinition.DEFINITION.getId()); if (portMin.equals(portMax)) { params.add(new ParameterValueBuilder().setName(new ParameterName(L4ClassifierDefinition.DST_PORT_PARAM)) .setIntValue(portMin.longValue()) .build()); } else { params.add(new ParameterValueBuilder() .setName(new ParameterName(L4ClassifierDefinition.DST_PORT_RANGE_PARAM)) .setRangeValue( new RangeValueBuilder().setMin(portMin.longValue()).setMax(portMax.longValue()).build()) .build()); } } Long protocol = getProtocol(secRule); if (protocol != null) { if (classifierBuilder.getClassifierDefinitionId() == null) { classifierBuilder.setClassifierDefinitionId(IpProtoClassifierDefinition.DEFINITION.getId()); } params.add(new ParameterValueBuilder() .setName(new ParameterName(IpProtoClassifierDefinition.PROTO_PARAM)) .setIntValue(protocol) .build()); } Long ethertype = getEtherType(secRule); if (ethertype != null) { if (classifierBuilder.getClassifierDefinitionId() == null) { classifierBuilder.setClassifierDefinitionId(EtherTypeClassifierDefinition.DEFINITION.getId()); } params.add(new ParameterValueBuilder() .setName(new ParameterName(EtherTypeClassifierDefinition.ETHERTYPE_PARAM)) .setIntValue(ethertype) .build()); } ClassifierName classifierName = SecRuleNameDecoder.getClassifierInstanceName(secRule); return classifierBuilder.setParameterValue(params).setName(new ClassifierName(classifierName)).build(); } private  SecRuleEntityDecoder(); static ContractId getContractId(SecurityRule secRule); static ClassifierInstance getClassifierInstance(SecurityRule secRule); static ActionRef createActionRefFromActionChoice(ActionChoice action); static ClassifierRef getClassifierRef(SecurityRule secRule); static Direction getDirection(SecurityRule secRule); static Clause getClause(SecurityRule secRule); static boolean isEtherTypeOfOneWithinTwo(SecurityRule one, SecurityRule two); static boolean isProtocolOfOneWithinTwo(SecurityRule one, SecurityRule two); static boolean isPortsOfOneWithinTwo(SecurityRule one, SecurityRule two); static Long getEtherType(SecurityRule secRule); static Long getProtocol(SecurityRule secRule);  }