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.rev160427.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);
26 private static final String METADATA_IP_PREFIX = "169.254.169.254/32";
27 private static final String OUT__METADATA = "Out__METADATA";
29 SourceMapper(ACE_DIRECTION direction) {
34 List<GbpAceBuilder> updateExtRules(List<GbpAceBuilder> rules, AddressEndpointWithLocation localEp,
35 ContainmentEndpoint cEp) {
36 // TODO external networking as a next step.
41 void updateRule(AddressEndpointWithLocation addrEp, GbpAceBuilder aclRuleBuilder) {
42 if (!EndpointUtils.getParentEndpoints(addrEp.getParentEndpointChoice()).isEmpty()) {
44 ParentEndpoint parentEp = EndpointUtils.getParentEndpoints(addrEp.getParentEndpointChoice()).get(0);
45 if (parentEp != null && parentEp.getContextType().isAssignableFrom(L3Context.class)) {
46 // TODO this is a fix for metadata agent in DHCP namespace, when we will fully support multiple IPs
47 // per interface we shall rework this
48 if (aclRuleBuilder.getName().contains(OUT__METADATA)) {
49 LOG.trace("Setting src IP address {} in rule {}", METADATA_IP_PREFIX, aclRuleBuilder);
51 AccessListUtil.setSourceL3Address(aclRuleBuilder, METADATA_IP_PREFIX);
52 } catch (UnknownHostException e) {
53 LOG.error("Failed to parse address {}. Cannot apply ACL entry {}. {}", METADATA_IP_PREFIX,
57 LOG.trace("Setting src IP address {} in rule {}", parentEp.getAddress(), aclRuleBuilder);
59 AccessListUtil.setSourceL3Address(aclRuleBuilder, parentEp.getAddress());
60 } catch (UnknownHostException e) {
61 LOG.error("Failed to parse address {}. Cannot apply ACL entry {}. {}", parentEp.getAddress(),