2 * Copyright (c) 2016 Cisco Systems, 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
9 package org.opendaylight.groupbasedpolicy.renderer.vpp.policy.acl;
11 import java.net.UnknownHostException;
12 import java.util.List;
14 import org.opendaylight.groupbasedpolicy.renderer.vpp.policy.acl.AccessListUtil.ACE_DIRECTION;
15 import org.opendaylight.groupbasedpolicy.util.EndpointUtils;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoints.containment.endpoints.ContainmentEndpoint;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.parent.child.endpoints.parent.endpoint.choice.parent.endpoint._case.ParentEndpoint;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.l2_l3.rev170511.L3Context;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.endpoints.AddressEndpointWithLocation;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 class SourceMapper extends AddressMapper {
25 private static final Logger LOG = LoggerFactory.getLogger(SourceMapper.class);
27 SourceMapper(ACE_DIRECTION direction) {
32 List<GbpAceBuilder> updateExtRules(List<GbpAceBuilder> rules, AddressEndpointWithLocation localEp,
33 ContainmentEndpoint cEp) {
34 // TODO external networking as a next step.
39 void updateRule(AddressEndpointWithLocation addrEp, GbpAceBuilder aclRuleBuilder) {
42 if (addrEp.getContextType().isAssignableFrom(L3Context.class)) {
43 address = addrEp.getAddress();
45 List<ParentEndpoint> parentEndpoints = EndpointUtils.getParentEndpoints(addrEp.getParentEndpointChoice());
46 if (parentEndpoints == null || parentEndpoints.isEmpty()
47 || !parentEndpoints.get(0).getContextType().isAssignableFrom(L3Context.class)) {
48 LOG.warn("Cannot resolve IP address for endpoint {}", addrEp);
51 address = parentEndpoints.get(0).getAddress();
53 LOG.trace("Setting src IP address {} in rule {}", address, aclRuleBuilder);
55 AccessListUtil.setSourceL3Address(aclRuleBuilder, address);
56 } catch (UnknownHostException e) {
57 LOG.error("Failed to parse address {}. Cannot apply ACL entry {}. {}", address, aclRuleBuilder, e);