From 2da2d410e5bd679b356b079972b441695c353833 Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Thu, 2 Jun 2016 13:23:39 +0200 Subject: Intializers for the new vlan model Change-Id: I513f0b190e9d9e669663a9a216e7c72b1ebeb10d Signed-off-by: Marek Gradzki --- v3po/api/src/main/yang/v3po.yang | 109 --------------------- .../fd/honeycomb/v3po/translate/util/RWUtils.java | 19 +++- .../v3po/initializers/InterfacesInitializer.java | 66 +++---------- .../SubInterfaceInitializationUtils.java | 66 +++++++++++++ .../v3po/interfacesstate/InterfaceUtils.java | 25 +++-- .../v3po/translate/v3po/util/NamingContext.java | 14 +-- 6 files changed, 111 insertions(+), 188 deletions(-) create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/initializers/SubInterfaceInitializationUtils.java (limited to 'v3po') diff --git a/v3po/api/src/main/yang/v3po.yang b/v3po/api/src/main/yang/v3po.yang index 18b82a9b0..f60070a4c 100644 --- a/v3po/api/src/main/yang/v3po.yang +++ b/v3po/api/src/main/yang/v3po.yang @@ -42,36 +42,6 @@ module v3po { "This type is used by to reference a bridged virtual interface"; } - // todo remove from v3po - /*typedef vlan-type { - type enumeration { - enum 802dot1q; - enum 802dot1ad; - } - }*/ - - // todo remove from v3po - /*typedef tag-rewrite-operation { - type enumeration { - enum disabled; - enum push-1; - enum push-2; - enum pop-1; - enum pop-2; - enum translate-1-to-1; - enum translate-1-to-2; - enum translate-2-to-1; - enum translate-2-to-2; - } - }*/ - - // todo remove from v3po - //typedef vlan-tag { - // type uint16 { - // range "1..4094"; - // } - //} - identity vxlan-tunnel { base if:interface-type; } @@ -152,41 +122,6 @@ module v3po { } } - // todo remove from v3po - /*grouping sub-interface-base-attributes { - leaf identifier { - type uint32; - } - leaf vlan-type { - type vlan-type; - default '802dot1q'; - } - leaf number-of-tags { - type uint8 { - range "0..2"; - } - default 1; - } - leaf outer-id { - type vlan-tag; - } - leaf inner-id { - type vlan-tag; - } - leaf match-any-outer-id { - type empty; - } - leaf match-any-inner-id { - type empty; - } - leaf exact-match { - type empty; - } - leaf default-subif { - type empty; - } - }*/ - grouping tap-interface-base-attributes { leaf tap-name { type string; @@ -309,24 +244,6 @@ module v3po { } } - // todo remove from v3po - /* grouping vlan-tag-rewrite-attributes { - leaf rewrite-operation { - type tag-rewrite-operation; - default 'disabled'; - } - leaf first-pushed { - type vlan-type; - default '802dot1q'; - } - leaf tag1 { - type vlan-tag; - } - leaf tag2 { - type vlan-tag; - } - }*/ - grouping l2-base-attributes { description "Parameters for configuring Layer2 features on interfaces."; @@ -380,15 +297,6 @@ module v3po { // 2. Only this augmentation with combination of ifc type is trigger to do something for vpp, what if user only configures base interface stuff ? + We need to get leaves defined by ietf-interfaces when we are processing this augment // 3. The ietf-interfaces model does not define groupings which makes types reuse difficult - /* - container sub-interface { - when "../if:type = 'v3po:sub-interface'"; - leaf super-interface { - type if:interface-ref; - } - uses sub-interface-base-attributes; - }*/ - container tap { when "../if:type = 'v3po:tap'"; uses tap-interface-base-attributes; @@ -422,10 +330,6 @@ module v3po { "not (../if:ipv6[if:enabled = 'true']/if:address/if:ip))"; uses l2-base-attributes; - - /*container vlan-tag-rewrite { - uses vlan-tag-rewrite-attributes; - }*/ } container vxlan-gpe { @@ -479,15 +383,6 @@ module v3po { type string; } - /* - container sub-interface { - when "../if:type = 'v3po:sub-interface'"; - leaf super-interface { - type if:interface-state-ref; - } - uses sub-interface-base-attributes; - }*/ - container tap { when "../if:type = 'v3po:tap'"; uses tap-interface-base-attributes; @@ -520,10 +415,6 @@ module v3po { "not (../if:ipv6[if:enabled = 'true']/if:address/if:ip))"; uses l2-base-attributes; - - /* container vlan-tag-rewrite { - uses vlan-tag-rewrite-attributes; - }*/ } } diff --git a/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/RWUtils.java b/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/RWUtils.java index dbfed04b0..b712e159c 100644 --- a/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/RWUtils.java +++ b/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/RWUtils.java @@ -21,13 +21,15 @@ import com.google.common.base.Preconditions; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; import com.google.common.collect.Maps; +import io.fd.honeycomb.v3po.translate.SubtreeManager; import io.fd.honeycomb.v3po.translate.read.ChildReader; import io.fd.honeycomb.v3po.translate.write.ChildWriter; -import io.fd.honeycomb.v3po.translate.SubtreeManager; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.stream.Collector; +import java.util.stream.Collectors; import javax.annotation.Nonnull; import org.opendaylight.yangtools.yang.binding.Augmentation; import org.opendaylight.yangtools.yang.binding.ChildOf; @@ -40,6 +42,21 @@ public final class RWUtils { private RWUtils() {} + /** + * Collector expecting only a single resulting item from a stream + */ + public static Collector singleItemCollector() { + return Collectors.collectingAndThen( + Collectors.toList(), + list -> { + if (list.size() != 1) { + throw new IllegalStateException("Unexpected size of list: " + list + ". Single item expected"); + } + return list.get(0); + } + ); + } + /** * Find next item in ID after provided type */ diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/initializers/InterfacesInitializer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/initializers/InterfacesInitializer.java index a41a6e87b..5a0e35dbd 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/initializers/InterfacesInitializer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/initializers/InterfacesInitializer.java @@ -16,6 +16,8 @@ package io.fd.honeycomb.v3po.translate.v3po.initializers; +import static io.fd.honeycomb.v3po.translate.v3po.initializers.SubInterfaceInitializationUtils.initializeSubinterfaceStateAugmentation; + import com.google.common.collect.Lists; import io.fd.honeycomb.v3po.vpp.data.init.AbstractDataTreeConverter; import javax.annotation.Nonnull; @@ -34,20 +36,16 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VxlanGpeVni; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.EthernetBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.L2Builder; -// import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.SubInterfaceBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.TapBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.VhostUserBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.VxlanBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.VxlanGpeBuilder; -// import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.l2.VlanTagRewriteBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.Ethernet; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.L2; -// import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.SubInterface; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.Tap; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.VhostUser; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.Vxlan; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.VxlanGpe; -// import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.l2.VlanTagRewrite; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.base.attributes.Interconnection; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.base.attributes.interconnection.BridgeBased; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.l2.base.attributes.interconnection.BridgeBasedBuilder; @@ -89,10 +87,19 @@ public class InterfacesInitializer extends AbstractDataTreeConverter SINGLE_ITEM_COLLECTOR = + RWUtils.singleItemCollector(); + private InterfaceUtils() { throw new UnsupportedOperationException("This utility class cannot be instantiated"); } @@ -147,11 +151,11 @@ public final class InterfaceUtils { /** * Queries VPP for interface description given interface key. * - * @param futureJvpp VPP Java Future API - * @param name interface name - * @param index VPP index of the interface - * @param ctx per-tx scope context containing cached dump with all the interfaces. If the cache is not - * available or outdated, another dump will be performed. + * @param futureJvpp VPP Java Future API + * @param name interface name + * @param index VPP index of the interface + * @param ctx per-tx scope context containing cached dump with all the interfaces. If the cache is not + * available or outdated, another dump will be performed. * @return SwInterfaceDetails DTO or null if interface was not found * @throws IllegalArgumentException If interface cannot be found */ @@ -198,13 +202,8 @@ public final class InterfaceUtils { } // SwInterfaceDump's name filter does prefix match, so we need additional filtering: - final SwInterfaceDetails iface = ifaces.swInterfaceDetails.stream().filter(d -> d.swIfIndex == index).collect( - Collectors.collectingAndThen(toList(), l -> { - if (l.size() == 1) { - return l.get(0); - } - throw new RuntimeException(); - })); + final SwInterfaceDetails iface = + ifaces.swInterfaceDetails.stream().filter(d -> d.swIfIndex == index).collect(SINGLE_ITEM_COLLECTOR); allInterfaces.put(index, iface); // update the cache return iface; } diff --git a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/NamingContext.java b/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/NamingContext.java index 34c810462..bcc980dd4 100644 --- a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/NamingContext.java +++ b/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/NamingContext.java @@ -21,8 +21,8 @@ import static com.google.common.base.Preconditions.checkState; import com.google.common.base.Optional; import io.fd.honeycomb.v3po.translate.MappingContext; +import io.fd.honeycomb.v3po.translate.util.RWUtils; import java.util.stream.Collector; -import java.util.stream.Collectors; import javax.annotation.Nonnull; 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.naming.context.rev160513.contexts.NamingContextKey; @@ -47,17 +47,7 @@ public final class NamingContext implements AutoCloseable { private final KeyedInstanceIdentifier namingContextIid; - /** - * Collector expecting only a single resulting item from a stream - */ - private static final Collector SINGLE_ITEM_COLLECTOR = Collectors.collectingAndThen( - Collectors.toList(), - list -> { - if (list.size() != 1) { - throw new IllegalStateException("Unexpected size of list: " + list + ". Single item expected"); - } - return list.get(0); - }); + private static final Collector SINGLE_ITEM_COLLECTOR = RWUtils.singleItemCollector(); /** * Create new naming context -- cgit 1.2.3-korg