2 * Copyright (c) 2016 Red Hat, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netvirt.aclservice;
10 import java.math.BigInteger;
11 import java.util.ArrayList;
12 import java.util.List;
15 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
16 import org.opendaylight.genius.mdsalutil.ActionInfo;
17 import org.opendaylight.genius.mdsalutil.InstructionInfo;
18 import org.opendaylight.genius.mdsalutil.MatchFieldType;
19 import org.opendaylight.genius.mdsalutil.MatchInfo;
20 import org.opendaylight.genius.mdsalutil.MatchInfoBase;
21 import org.opendaylight.genius.mdsalutil.NwConstants;
22 import org.opendaylight.genius.mdsalutil.NxMatchFieldType;
23 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
24 import org.opendaylight.netvirt.aclservice.api.AclServiceManager.Action;
25 import org.opendaylight.netvirt.aclservice.utils.AclConstants;
26 import org.opendaylight.netvirt.aclservice.utils.AclServiceOFFlowBuilder;
27 import org.opendaylight.netvirt.aclservice.utils.AclServiceUtils;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.Ace;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.Matches;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.AceType;
31 import 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.AceIp;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.DirectionIngress;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.SecurityRuleAttr;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.AllowedAddressPairs;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
39 * Provides the stateless implementation for ingress (w.r.t VM) ACL service.
42 * Note: Table names used are w.r.t switch. Hence, switch ingress is VM egress
45 public class StatelessIngressAclServiceImpl extends AbstractIngressAclServiceImpl {
47 private static final Logger LOG = LoggerFactory.getLogger(StatelessIngressAclServiceImpl.class);
49 public StatelessIngressAclServiceImpl(DataBroker dataBroker, IMdsalApiManager mdsalManager) {
50 super(dataBroker, mdsalManager);
54 protected void programSpecificFixedRules(BigInteger dpid, String dhcpMacAddress,
55 List<AllowedAddressPairs> allowedAddresses, int lportTag, String portId, Action action, int addOrRemove) {
59 protected String syncSpecificAclFlow(BigInteger dpId, int lportTag, int addOrRemove, Ace ace, String portId,
60 Map<String, List<MatchInfoBase>> flowMap, String flowName) {
61 // Not in use here. programAceRule function is overridden.
66 protected void programAceRule(BigInteger dpId, int lportTag, int addOrRemove, Ace ace, String portId,
67 List<AllowedAddressPairs> syncAllowedAddresses) {
68 SecurityRuleAttr aceAttr = AclServiceUtils.getAccesssListAttributes(ace);
69 if (!aceAttr.getDirection().equals(DirectionIngress.class)) {
72 Matches matches = ace.getMatches();
73 AceType aceType = matches.getAceType();
74 Map<String, List<MatchInfoBase>> flowMap = null;
75 Short protocol = null;
77 if (aceType instanceof AceIp) {
78 protocol = ((AceIp)aceType).getProtocol();
79 flowMap = AclServiceOFFlowBuilder.programIpFlow(matches);
81 if (null == flowMap) {
82 LOG.error("Failed to apply ACL {} lPortTag {}", ace.getKey(), lportTag);
85 for (Map.Entry<String, List<MatchInfoBase>> flow : flowMap.entrySet()) {
86 List<MatchInfoBase> flowMatches = flow.getValue();
87 boolean hasTcpDstMatch = AclServiceUtils.containsMatchFieldType(flowMatches,
88 NxMatchFieldType.nx_tcp_dst_with_mask);
89 if (hasTcpDstMatch || protocol == null) {
90 String flowName = flow.getKey() + "Ingress" + lportTag + ace.getKey().getRuleName();
91 flowMatches.add(AclServiceUtils.buildLPortTagMatch(lportTag));
92 programAllowSynRules(dpId, flowName, flowMatches, addOrRemove);
97 private void programAllowSynRules(BigInteger dpId, String origFlowName,
98 List<MatchInfoBase> origFlowMatches, int addOrRemove) {
99 List<MatchInfoBase> flowMatches = new ArrayList<>();
100 flowMatches.addAll(origFlowMatches);
101 flowMatches.add(new MatchInfo(MatchFieldType.tcp_flags, new long[] { AclConstants.TCP_FLAG_SYN }));
102 List<ActionInfo> actionsInfos = new ArrayList<>();
103 List<InstructionInfo> instructions = getDispatcherTableResubmitInstructions(actionsInfos);
105 String flowName = "SYN_" + origFlowName;
106 syncFlow(dpId, NwConstants.EGRESS_ACL_TABLE, flowName, AclConstants.PROTO_MATCH_SYN_ALLOW_PRIORITY,
107 "ACL_SYN_", 0, 0, AclConstants.COOKIE_ACL_BASE, flowMatches, instructions, addOrRemove);
108 String oper = getOperAsString(addOrRemove);
109 LOG.debug("{} allow syn packet flow {}", oper, flowName);