summaryrefslogtreecommitdiffstats
path: root/infra/it/pom.xml
blob: d30c39c972911c1fa6d0844122cb8ba1a3b3aa5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?xml version="1.0" encoding="UTF-8"?>
<!--
 Copyright (c) 2015 Cisco and/or its affiliates.
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at:

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <parent>
    <groupId>io.fd.honeycomb.common</groupId>
    <artifactId>honeycomb-parent</artifactId>
    <version>1.18.04</version>
    <relativePath>../../common/honeycomb-parent</relativePath>
  </parent>

  <groupId>io.fd.honeycomb.it</groupId>
  <artifactId>honeycomb-it-aggregator</artifactId>
  <version>1.18.04</version>
  <name>honeycomb-it</name>
  <packaging>pom</packaging>
  <modelVersion>4.0.0</modelVersion>

  <modules>
    <module>test-model</module>
    <module>it-test</module>
  </modules>

  <profiles>
    <!-- Activate from command line with mvn <goals> -Pbenchmark -->
    <profile>
      <id>benchmark</id>
      <modules>
        <module>benchmark</module>
      </modules>
    </profile>

    <!-- Activate management module -->
    <profile>
      <id>management</id>
      <modules>
        <module>management</module>
      </modules>
    </profile>

    <!-- Activate memory benchmarking modules -->
    <profile>
      <id>memory-benchmark</id>
      <modules>
        <module>management</module>
        <module>memory-benchmark-scripts</module>
        <module>memory-benchmark</module>
        <module>memory-benchmark-api</module>
      </modules>
    </profile>
  </profiles>

  <!-- DO NOT install or deploy the repo root pom as it's only needed to initiate a build -->
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-deploy-plugin</artifactId>
        <configuration>
          <skip>true</skip>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-install-plugin</artifactId>
        <configuration>
          <skip>true</skip>
        </configuration>
      </plugin>
    </plugins>
  </build>

</project>
"o">; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Optional; import io.fd.honeycomb.translate.MappingContext; import io.fd.honeycomb.translate.vpp.util.Ipv4Translator; import io.fd.vpp.jvpp.snat.dto.SnatStaticMappingDetails; import java.util.Collections; import java.util.Comparator; import java.util.List; import javax.annotation.Nonnull; import javax.annotation.concurrent.ThreadSafe; import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.Contexts; import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.nat.context.rev161214.NatMappingEntryCtxAugmentation; import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.nat.context.rev161214.mapping.entry.context.attributes.NatMappingEntryContext; import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.nat.context.rev161214.mapping.entry.context.attributes.nat.mapping.entry.context.NatInstance; import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.nat.context.rev161214.mapping.entry.context.attributes.nat.mapping.entry.context.NatInstanceKey; import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.nat.context.rev161214.mapping.entry.context.attributes.nat.mapping.entry.context.nat.instance.MappingTable; import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.nat.context.rev161214.mapping.entry.context.attributes.nat.mapping.entry.context.nat.instance.mapping.table.MappingEntry; import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.nat.context.rev161214.mapping.entry.context.attributes.nat.mapping.entry.context.nat.instance.mapping.table.MappingEntryBuilder; import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.nat.context.rev161214.mapping.entry.context.attributes.nat.mapping.entry.context.nat.instance.mapping.table.MappingEntryKey; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Context tracker for Nat Mapping entries. */ @ThreadSafe public class MappingEntryContext implements Ipv4Translator { private static final Logger LOG = LoggerFactory.getLogger(MappingEntryContext.class); /** * Add mapping entry to index mapping to context. */ public synchronized void addEntry(final long natInstanceId, final long entryId, @Nonnull final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.nat.instance.mapping.table.MappingEntry entry, @Nonnull final MappingContext mappingContext) { final InstanceIdentifier<MappingEntry> id = getId(natInstanceId, entryToKey(entry)); checkArgument(!containsEntry(natInstanceId, entry, mappingContext), "Mapping for %s already present", id); mappingContext.put(id, toCtxMapEntry(entry, entryId)); } /** * Check whether mapping entry to index mapping already exists in context. */ public synchronized boolean containsEntry(final long natInstanceId, @Nonnull final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.nat.instance.mapping.table.MappingEntry entry, @Nonnull final MappingContext mappingContext) { final InstanceIdentifier<MappingEntry> id = getId(natInstanceId, entryToKey(entry)); return mappingContext.read(id).isPresent(); } @VisibleForTesting static InstanceIdentifier<MappingEntry> getId(final Long natInstanceId, final MappingEntryKey key) { return getTableId(natInstanceId).child(MappingEntry.class, key); } @VisibleForTesting static InstanceIdentifier<MappingTable> getTableId(final long natInstanceId) { return InstanceIdentifier.create(Contexts.class) .augmentation(NatMappingEntryCtxAugmentation.class) .child(NatMappingEntryContext.class) .child(NatInstance.class, new NatInstanceKey(natInstanceId)) .child(MappingTable.class); } @VisibleForTesting static MappingEntryKey entryToKey( final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.nat.instance.mapping.table.MappingEntry entry) { // Only IPv4 return new MappingEntryKey(new IpAddress(entry.getExternalSrcAddress()), entry.getInternalSrcAddress()); } private MappingEntryKey entryToKey(final SnatStaticMappingDetails entry) { // Only IPv4 return new MappingEntryKey( new IpAddress(new Ipv4Address(arrayToIpv4AddressNoZoneReversed(entry.externalIpAddress))), new IpAddress(new Ipv4Address(arrayToIpv4AddressNoZoneReversed(entry.localIpAddress)))); } private boolean equalEntries(final SnatStaticMappingDetails detail, final MappingEntry ctxMappingEntry) { final IpAddress internalAddrFromDetails = new IpAddress(new Ipv4Address(arrayToIpv4AddressNoZoneReversed(detail.localIpAddress))); // Only IPv4 if (!ctxMappingEntry.getInternal().equals(internalAddrFromDetails)) { return false; } // Only IPv4 final IpAddress externalAddrFromDetails = new IpAddress(new Ipv4Address(arrayToIpv4AddressNoZoneReversed(detail.externalIpAddress))); if (!ctxMappingEntry.getExternal().equals(externalAddrFromDetails)) { return false; } return true; } @VisibleForTesting static MappingEntry toCtxMapEntry( @Nonnull final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.nat.instance.mapping.table.MappingEntry entry, final long entryId) { return new MappingEntryBuilder() .setKey(entryToKey(entry)) .setIndex(entryId) .build(); } private MappingEntry toCtxMapEntry(@Nonnull final SnatStaticMappingDetails details, final long entryId) { return new MappingEntryBuilder() .setKey(entryToKey(details)) .setIndex(entryId) .build(); } /** * Delete mapping of mapping entry to index from context. */ public synchronized void removeEntry(final long natInstanceId, @Nonnull final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.nat.instance.mapping.table.MappingEntry entry, @Nonnull final MappingContext mappingContext) { mappingContext.delete(getId(natInstanceId, entryToKey(entry))); } /** * Find specific details in provided collection identified with provided index. */ public synchronized SnatStaticMappingDetails findDetails(@Nonnull final List<SnatStaticMappingDetails> details, final long natInstanceId, final long idx, @Nonnull final MappingContext mappingContext) { // Find mapping entry for Index final MappingEntry ctxMappingEntry = mappingContext.read(getTableId(natInstanceId)) .transform(MappingTable::getMappingEntry) .or(Collections.emptyList()) .stream() .filter(entry -> entry.getIndex() == idx) .findFirst() .orElseThrow(() -> new IllegalStateException("Unable to find context mapping for nat-instance: " + natInstanceId + " and ID: " + idx)); // Find which details matches the context stored entry under index return details.stream() .filter(detail -> equalEntries(detail, ctxMappingEntry)) .findFirst() .orElseThrow(() -> new IllegalStateException("Unable to match mapping for nat-instance: " + natInstanceId + " and match: " + ctxMappingEntry + " in: " + details)); } /** * Get index for a mapping entry details or create an artificial one. */ public synchronized long getStoredOrArtificialIndex(final Long natInstanceId, @Nonnull final SnatStaticMappingDetails details, @Nonnull final MappingContext mappingContext) { return mappingContext.read(getId(natInstanceId, entryToKey(details))) .transform(MappingEntry::getIndex) .or(() -> getArtificialId(details, natInstanceId, mappingContext)); } /** * Get index for a stored mapping entry. */ public synchronized Optional<Long> getStoredIndex(final long natInstanceId, @Nonnull final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.nat.instance.mapping.table.MappingEntry entry, @Nonnull final MappingContext mappingContext) { return mappingContext.read(getId(natInstanceId, entryToKey(entry))) .transform(MappingEntry::getIndex); } private long getArtificialId(final SnatStaticMappingDetails details, final Long natInstanceId, final MappingContext mappingContext) { LOG.trace("Assigning artificial ID for {}", details); final long artificialIdx = findFreeIndex(natInstanceId, mappingContext); LOG.debug("Artificial ID for {} assigned as: {}", details, artificialIdx); mappingContext.put(getId(natInstanceId, entryToKey(details)), toCtxMapEntry(details, artificialIdx)); return artificialIdx; } private long findFreeIndex(final long natInstanceId, final MappingContext mappingContext) { return mappingContext.read(getTableId(natInstanceId)) .transform(MappingTable::getMappingEntry) .or(Collections.emptyList()) .stream() .map(MappingEntry::getIndex) .max(Comparator.naturalOrder()) .map(i -> i + 1) .orElse(0L); } }