Bug 8228 - metadata service fix made cleaner
[groupbasedpolicy.git] / renderers / vpp / src / main / java / org / opendaylight / groupbasedpolicy / renderer / vpp / policy / acl / DestinationMapper.java
index 1eca68663e8331214af4fa0e6dd521880d8507cc..73c2bbdfd79af567d654d1b94294eeae18ce8c60 100644 (file)
@@ -23,8 +23,6 @@ import org.slf4j.LoggerFactory;
 class DestinationMapper extends AddressMapper {
 
     private static final Logger LOG = LoggerFactory.getLogger(DestinationMapper.class);
-    private static final String METADATA_IP_PREFIX = "169.254.169.254/32";
-    private static final String IN__METADATA = "In__METADATA";
 
     DestinationMapper(ACE_DIRECTION direction) {
         super(direction);
@@ -39,31 +37,22 @@ class DestinationMapper extends AddressMapper {
 
     @Override
     void updateRule(AddressEndpointWithLocation addrEp, GbpAceBuilder aclRuleBuilder) {
-        if (!EndpointUtils.getParentEndpoints(addrEp.getParentEndpointChoice()).isEmpty()) {
-            // TODO more parents, when supported
+        String address;
+        if (addrEp.getContextType().isAssignableFrom(L3Context.class)) {
+            address = addrEp.getAddress();
+        } else {
             ParentEndpoint parentEp = EndpointUtils.getParentEndpoints(addrEp.getParentEndpointChoice()).get(0);
-            if (parentEp != null && parentEp.getContextType().isAssignableFrom(L3Context.class)) {
-                // TODO this is a fix for metadata agent in DHCP namespace, when we will fully support multiple IPs
-                // per interface we shall rework this
-                if (aclRuleBuilder.getName().contains(IN__METADATA)) {
-                    LOG.trace("Setting dst IP address {} in rule {}", METADATA_IP_PREFIX, aclRuleBuilder);
-                    try {
-                        AccessListUtil.setDestinationL3Address(aclRuleBuilder, METADATA_IP_PREFIX);
-                    } catch (UnknownHostException e) {
-                        LOG.error("Failed to parse address {}. Cannot apply ACL entry {}. {}", METADATA_IP_PREFIX,
-                            aclRuleBuilder, e);
-                    }
-                } else {
-                    LOG.trace("Setting dst IP address {} in rule {}", parentEp.getAddress(), aclRuleBuilder);
-                    try {
-                        AccessListUtil.setDestinationL3Address(aclRuleBuilder, parentEp.getAddress());
-                    } catch (UnknownHostException e) {
-                        LOG.error("Failed to parse address {}. Cannot apply ACL entry {}. {}", parentEp.getAddress(),
-                            aclRuleBuilder, e);
-                    }
-                }
-
+            if (parentEp == null || !parentEp.getContextType().isAssignableFrom(L3Context.class)) {
+                LOG.warn("Cannot resolve IP address for endpoint {}", addrEp);
+                return;
             }
+            address = parentEp.getAddress();
+        }
+        LOG.trace("Setting dst IP address {} in rule {}", address, aclRuleBuilder);
+        try {
+            AccessListUtil.setDestinationL3Address(aclRuleBuilder, address);
+        } catch (UnknownHostException e) {
+            LOG.error("Failed to parse address {}. Cannot apply ACL entry {}. {}", address, aclRuleBuilder, e);
         }
     }
 }