Search in sources :

Example 1 with PermitBuilder

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.actions.packet.handling.PermitBuilder in project netvirt by opendaylight.

the class NeutronSecurityRuleListener method toAceBuilder.

private AceBuilder toAceBuilder(SecurityRule securityRule) {
    AceIpBuilder aceIpBuilder = new AceIpBuilder();
    SecurityRuleAttrBuilder securityRuleAttrBuilder = new SecurityRuleAttrBuilder();
    DestinationPortRangeBuilder destinationPortRangeBuilder = new DestinationPortRangeBuilder();
    boolean isDirectionIngress = false;
    if (securityRule.getDirection() != null) {
        securityRuleAttrBuilder.setDirection(DIRECTION_MAP.get(securityRule.getDirection()));
        isDirectionIngress = securityRule.getDirection().equals(DirectionIngress.class);
    }
    if (securityRule.getPortRangeMax() != null) {
        destinationPortRangeBuilder.setUpperPort(new PortNumber(securityRule.getPortRangeMax()));
    }
    if (securityRule.getPortRangeMin() != null) {
        destinationPortRangeBuilder.setLowerPort(new PortNumber(securityRule.getPortRangeMin()));
        // set destination port range if lower port is specified as it is mandatory parameter in acl model
        aceIpBuilder.setDestinationPortRange(destinationPortRangeBuilder.build());
    }
    aceIpBuilder = handleRemoteIpPrefix(securityRule, aceIpBuilder, isDirectionIngress);
    if (securityRule.getRemoteGroupId() != null) {
        securityRuleAttrBuilder.setRemoteGroupId(securityRule.getRemoteGroupId());
    }
    if (securityRule.getProtocol() != null) {
        SecurityRuleAttributes.Protocol protocol = securityRule.getProtocol();
        if (protocol.getUint8() != null) {
            // uint8
            aceIpBuilder.setProtocol(protocol.getUint8());
        } else {
            // symbolic protocol name
            aceIpBuilder.setProtocol(PROTOCOL_MAP.get(protocol.getIdentityref()));
        }
    }
    MatchesBuilder matchesBuilder = new MatchesBuilder();
    matchesBuilder.setAceType(aceIpBuilder.build());
    // set acl action as permit for the security rule
    ActionsBuilder actionsBuilder = new ActionsBuilder();
    actionsBuilder.setPacketHandling(new PermitBuilder().setPermit(true).build());
    AceBuilder aceBuilder = new AceBuilder();
    aceBuilder.setKey(new AceKey(securityRule.getUuid().getValue()));
    aceBuilder.setRuleName(securityRule.getUuid().getValue());
    aceBuilder.setMatches(matchesBuilder.build());
    aceBuilder.setActions(actionsBuilder.build());
    aceBuilder.addAugmentation(SecurityRuleAttr.class, securityRuleAttrBuilder.build());
    return aceBuilder;
}
Also used : SecurityRuleAttributes(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.secgroups.rev150712.SecurityRuleAttributes) DirectionIngress(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.DirectionIngress) MatchesBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.MatchesBuilder) AceKey(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.AceKey) ActionsBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.ActionsBuilder) DestinationPortRangeBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160218.acl.transport.header.fields.DestinationPortRangeBuilder) AceBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.AceBuilder) AceIpBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.AceIpBuilder) SecurityRuleAttrBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.SecurityRuleAttrBuilder) PermitBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.actions.packet.handling.PermitBuilder) PortNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber)

Aggregations

AceBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.AceBuilder)1 AceKey (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.AceKey)1 ActionsBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.ActionsBuilder)1 MatchesBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.MatchesBuilder)1 PermitBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.actions.packet.handling.PermitBuilder)1 AceIpBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.AceIpBuilder)1 PortNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber)1 DestinationPortRangeBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160218.acl.transport.header.fields.DestinationPortRangeBuilder)1 SecurityRuleAttrBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.SecurityRuleAttrBuilder)1 DirectionIngress (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.DirectionIngress)1 SecurityRuleAttributes (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.secgroups.rev150712.SecurityRuleAttributes)1