.map(ace -> {
final VppAce standardAce = fromStandardAce(ace);
- // pre-bind rule with protocol based attributes
+ // pre-bind rule with protocol based attributes (if present)
AclRule rule = createPreBindRule(standardAce);
rule.isPermit = standardAction(ace);
return portNumber.getValue().shortValue();
}
+ /**
+ * Pre-bind rule with protocol based attributes (if present).
+ *
+ * @param vppAce rule to be processed
+ * @return AclRule with protocol filled protocol fields
+ */
default AclRule createPreBindRule(@Nonnull final VppAce vppAce) {
AclRule rule = new AclRule();
- rule.proto = protocol(vppAce.getVppAceNodes().getIpProtocol());
+
+ final IpProtocol ipProtocol = vppAce.getVppAceNodes().getIpProtocol();
+ if (ipProtocol == null) {
+ // returns AclRule with rule.proto set to 0 (protocol fields will be ignored by vpp)
+ return rule;
+ }
+
+ rule.proto = protocol(ipProtocol);
switch (rule.proto) {
case ICMP_INDEX: {
@RunWith(HoneycombTestRunner.class)
public class ProtoPreBindRuleProducerTest implements ProtoPreBindRuleProducer, AclTestSchemaContext {
+ private static final byte IGNORE_PROTOCOL = 0;
//TODO - remove after resolving how to address identity from different model in textual yang instance identifier
private VppAce extractAce(AccessLists accessLists) {
assertEquals(0, icmpRule.tcpFlagsValue);
}
+ @Test
+ public void tesProtocolNotSpecified(@InjectTestData(resourcePath = "/rules/no-protocol-rule.json") AccessLists acls) {
+ final AclRule noProtocolRule = createPreBindRule(extractAce(acls));
+
+ assertEquals(IGNORE_PROTOCOL, noProtocolRule.proto);
+ }
+
}
\ No newline at end of file
--- /dev/null
+{
+ "access-lists": {
+ "acl": [
+ {
+ "acl-name": "standard-acl",
+ "acl-type": "vpp-acl:vpp-acl",
+ "access-list-entries": {
+ "ace": [
+ {
+ "rule-name": "no-protocol-rule",
+ "matches": {
+ "vpp-ace-nodes": {
+ "destination-ipv4-network": "192.168.2.1/32",
+ "source-ipv4-network": "192.168.2.2/32"
+ }
+ }
+ }
+ ]
+ }
+ }
+ ]
+ }
+}
\ No newline at end of file