diff options
author | Maros Marsalek <mmarsale@cisco.com> | 2016-04-13 10:44:12 +0200 |
---|---|---|
committer | Maros Marsalek <mmarsale@cisco.com> | 2016-04-13 12:17:44 +0200 |
commit | 036a3589cfc1a62eddb49dc9cf09b7949c313f9b (patch) | |
tree | 6c9dfeba3743aabeccd18d5d7aede1e1722a5bac /v3po/impl/src | |
parent | d98b39ae51b94b5442718c668c4a5353e79e3c0c (diff) |
HONEYCOMB-9: Remove initial Honeycomb pipeline
+ Rewire global restconf to only serve VPP requests
+ Remove artificial Honeycomb mountpoint
Change-Id: I90738123e46a9fb29db19ee09fd139b57cd8af10
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
Diffstat (limited to 'v3po/impl/src')
21 files changed, 256 insertions, 2513 deletions
diff --git a/v3po/impl/src/main/config/default-config.xml b/v3po/impl/src/main/config/default-config.xml index fac06e136..40478b7cc 100644 --- a/v3po/impl/src/main/config/default-config.xml +++ b/v3po/impl/src/main/config/default-config.xml @@ -168,26 +168,14 @@ <module> <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:v3po:impl">prefix:v3po</type> <name>v3po-default</name> - <broker> - <type xmlns:binding="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">binding:binding-broker-osgi-registry</type> - <name>binding-osgi-broker</name> - </broker> <dom-broker> <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom">prefix:dom-broker-osgi-registry</type> <name>dom-broker</name> </dom-broker> - <vpp-japi> - <type xmlns:prefix="urn:honeycomb:params:xml:ns:yang:vpp:japi:cfg">prefix:vpp-japi</type> - <name>vpp-japi</name> - </vpp-japi> - <serializer> - <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding:impl">prefix:binding-dom-mapping-service</type> - <name>runtime-mapping-singleton</name> - </serializer> - <dom-data-broker> + <honeycomb-dom-data-broker> <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom">prefix:dom-async-data-broker</type> <name>honeycomb-dom-data-broker</name> - </dom-data-broker> + </honeycomb-dom-data-broker> </module> <!-- Config initialization --> diff --git a/v3po/impl/src/main/config/restconf-north-config.xml b/v3po/impl/src/main/config/restconf-north-config.xml new file mode 100644 index 000000000..ff2cdac18 --- /dev/null +++ b/v3po/impl/src/main/config/restconf-north-config.xml @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Copyright (c) 2016 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. + --> +<snapshot> + <configuration> + <data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> + <modules xmlns="urn:opendaylight:params:xml:ns:yang:controller:config"> + <module> + <type xmlns:rest="urn:opendaylight:params:xml:ns:yang:controller:md:sal:rest:connector">rest:rest-connector-impl</type> + <name>rest-connector-default-impl</name> + <!-- Reconfiguring the default restconf northbound instance, to wire it just to honeycomb broker facade --> + <dom-broker> + <type xmlns:dom="urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom">dom:dom-broker-osgi-registry</type> + <name>vpp-dom-broker</name> + </dom-broker> + </module> + </modules> + </data> + </configuration> + <required-capabilities> + <capability>urn:opendaylight:params:xml:ns:yang:controller:sal:restconf:service?module=sal-restconf-service&revision=2015-07-08</capability> + <capability>urn:opendaylight:params:xml:ns:yang:controller:md:sal:rest:connector?module=opendaylight-rest-connector&revision=2014-07-24</capability> + </required-capabilities> +</snapshot> diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/DataRegistry.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/DataRegistry.java deleted file mode 100644 index 5888dc998..000000000 --- a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/DataRegistry.java +++ /dev/null @@ -1,24 +0,0 @@ -/*
- * 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.
- */
-
-package io.fd.honeycomb.v3po.impl;
-
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
-public interface DataRegistry {
- <T extends DataObject> void registerModule(InstanceIdentifier<T> path, DataResolver<T> resolver);
-}
diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/DataResolver.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/DataResolver.java deleted file mode 100644 index 5ada80f86..000000000 --- a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/DataResolver.java +++ /dev/null @@ -1,26 +0,0 @@ -/*
- * 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.
- */
-
-package io.fd.honeycomb.v3po.impl;
-
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
-public interface DataResolver<T extends DataObject> {
- public void resolve(InstanceIdentifier<T> path, WriteTransaction tx);
-}
-
diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/DataResolverInterfaceState.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/DataResolverInterfaceState.java deleted file mode 100644 index fd2d48c01..000000000 --- a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/DataResolverInterfaceState.java +++ /dev/null @@ -1,36 +0,0 @@ -/*
- * 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.
- */
-
-
-package io.fd.honeycomb.v3po.impl;
-
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
-// Return Interface data from interfaces.state based on InstanceIdentifier
-public class DataResolverInterfaceState implements DataResolver<Interface> {
-
- @Override
- public void resolve(InstanceIdentifier<Interface> path,
- WriteTransaction tx) {
- InterfaceKey key = path.firstKeyOf(Interface.class);
- String interfaceName = key.getName();
-
- return;
- }
-}
diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/InterfaceStateIpv4Builder.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/InterfaceStateIpv4Builder.java deleted file mode 100644 index 5e2141d6f..000000000 --- a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/InterfaceStateIpv4Builder.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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. - */ - -package io.fd.honeycomb.v3po.impl; - -import java.util.ArrayList; -import java.util.List; - -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.IpAddressOrigin; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.NeighborOrigin; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4Builder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.AddressBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.Neighbor; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.NeighborBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.address.subnet.PrefixLength; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.address.subnet.PrefixLengthBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; - -public class InterfaceStateIpv4Builder { - private List<Address> addrs = new ArrayList<Address>(); - private List<Neighbor> neighbors = new ArrayList<Neighbor>(); - private Ipv4Builder ipv4Builder = new Ipv4Builder(); - - /** - * TODO-ADD-JAVADOC. - */ - public void addAddress(String ipv4Addr, short prefixLength, IpAddressOrigin origin) { - // address - AddressBuilder addrBuilder = new AddressBuilder(); - - // IpAddressOrigin.Static - addrBuilder.setOrigin(origin); // FIXME: how to find origin? - - PrefixLength prefixLen = new PrefixLengthBuilder().setPrefixLength(prefixLength).build(); - addrBuilder.setSubnet(prefixLen); - - addrBuilder.setIp(new Ipv4AddressNoZone(ipv4Addr)); - - addrs.add(addrBuilder.build()); - } - - /** - * TODO-ADD-JAVADOC. - */ - public void addNeighbor(String ipv4Addr, String physAddr, NeighborOrigin origin) { - // address neighbor - NeighborBuilder nbrBuilder = new NeighborBuilder(); - nbrBuilder.setIp(new Ipv4AddressNoZone(ipv4Addr)); - nbrBuilder.setLinkLayerAddress(new PhysAddress(physAddr)); // TODO ("00:00:00:00:00:00") - nbrBuilder.setOrigin(origin); - - neighbors.add(nbrBuilder.build()); - } - - /** - * TODO-ADD-JAVADOC. - */ - public void setForwarding(boolean fwd) { - ipv4Builder.setForwarding(fwd); - } - - /** - * TODO-ADD-JAVADOC. - */ - public void setMtu(int mtu) { - ipv4Builder.setMtu(mtu); - } - - /** - * TODO-ADD-JAVADOC. - */ - public Ipv4 build() { - ipv4Builder.setAddress(addrs); - ipv4Builder.setNeighbor(neighbors); - return ipv4Builder.build(); - } -} - diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/InterfaceStateIpv6Builder.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/InterfaceStateIpv6Builder.java deleted file mode 100644 index 42862a944..000000000 --- a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/InterfaceStateIpv6Builder.java +++ /dev/null @@ -1,87 +0,0 @@ -/*
- * 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.
- */
-
-package io.fd.honeycomb.v3po.impl;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.IpAddressOrigin;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.NeighborOrigin;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv6;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv6Builder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv6.Address;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv6.AddressBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv6.Neighbor;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv6.NeighborBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
-
-public class InterfaceStateIpv6Builder {
- private List<Address> addrs = new ArrayList<Address>();
- private List<Neighbor> neighbors = new ArrayList<Neighbor>();
- private Ipv6Builder ipv6Builder = new Ipv6Builder();
-
- /**
- * TODO-ADD-JAVADOC.
- */
- public void addAddress(String ipv6Addr, short prefixLength, IpAddressOrigin origin) {
- // address
- AddressBuilder addrBuilder = new AddressBuilder();
-
- // IpAddressOrigin.Static
- addrBuilder.setOrigin(origin); // FIXME: how to find origin?
- addrBuilder.setPrefixLength(prefixLength);
- addrBuilder.setIp(new Ipv6AddressNoZone(ipv6Addr));
-
- addrs.add(addrBuilder.build());
- }
-
- /**
- * TODO-ADD-JAVADOC.
- */
- public void addNeighbor(String ipv6Addr, String physAddr, NeighborOrigin origin) {
- // address neighbor
- NeighborBuilder nbrBuilder = new NeighborBuilder();
- nbrBuilder.setIp(new Ipv6AddressNoZone(ipv6Addr));
- nbrBuilder.setLinkLayerAddress(new PhysAddress(physAddr)); // TODO ("00:00:00:00:00:00")
- nbrBuilder.setOrigin(origin);
-
- neighbors.add(nbrBuilder.build());
- }
-
- /**
- * TODO-ADD-JAVADOC.
- */
- public void setForwarding(boolean fwd) {
- ipv6Builder.setForwarding(fwd);
- }
-
- /**
- * TODO-ADD-JAVADOC.
- */
- public void setMtu(long mtu) {
- ipv6Builder.setMtu(mtu);
- }
-
- /**
- * TODO-ADD-JAVADOC.
- */
- public Ipv6 build() {
- ipv6Builder.setAddress(addrs);
- ipv6Builder.setNeighbor(neighbors);
- return ipv6Builder.build();
- }
-}
diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/LoggingFuturesCallBack.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/LoggingFuturesCallBack.java deleted file mode 100644 index 33c395d1f..000000000 --- a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/LoggingFuturesCallBack.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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. - */ - -package io.fd.honeycomb.v3po.impl; - -import com.google.common.util.concurrent.FutureCallback; -import org.slf4j.Logger; - -public class LoggingFuturesCallBack<V> implements FutureCallback<V> { - - private final Logger log; - private final String message; - - public LoggingFuturesCallBack(final String message, final Logger log) { - this.message = message; - this.log = log; - } - - @Override - public void onFailure(final Throwable err) { - log.warn(message,err); - } - - @Override - public void onSuccess(final V arg0) { - /* suppress success messages - if (arg0 == null) { - LOG.info("Success!"); - } else { - LOG.info("Success! {}", arg0); - } - */ - } -} diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/NetconfFacadeHoneycombBindingBroker.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/NetconfFacadeHoneycombBindingBroker.java new file mode 100644 index 000000000..9d70113e4 --- /dev/null +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/NetconfFacadeHoneycombBindingBroker.java @@ -0,0 +1,200 @@ +/* + * 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. + */ + +package io.fd.honeycomb.v3po.impl; + +import com.google.common.base.Optional; +import com.google.common.collect.Maps; +import com.google.common.util.concurrent.CheckedFuture; +import com.google.common.util.concurrent.Futures; +import java.util.Map; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import javax.annotation.concurrent.NotThreadSafe; +import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; +import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint; +import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService; +import org.opendaylight.controller.md.sal.dom.api.DOMRpcAvailabilityListener; +import org.opendaylight.controller.md.sal.dom.api.DOMRpcException; +import org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementationNotAvailableException; +import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult; +import org.opendaylight.controller.md.sal.dom.api.DOMRpcService; +import org.opendaylight.controller.sal.core.api.Broker; +import org.opendaylight.controller.sal.core.api.BrokerService; +import org.opendaylight.controller.sal.core.api.Consumer; +import org.opendaylight.controller.sal.core.api.Provider; +import org.opendaylight.controller.sal.core.api.model.SchemaService; +import org.opendaylight.controller.sal.core.api.mount.MountProvisionListener; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; +import org.opendaylight.yangtools.yang.model.api.SchemaPath; +import org.osgi.framework.BundleContext; + +/** + * Implementation of dom broker to facade VPP pipeline for netconf northbound server + */ +public class NetconfFacadeHoneycombBindingBroker implements AutoCloseable, Broker { + + private static final BrokerService EMPTY_DOM_RPC_SERVICE = new EmptyDomRpcService(); + private static final BrokerService EMPTY_DOM_MOUNT_SERVICE = new EmptyDomMountService(); + + private Map<Class<? extends BrokerService>, BrokerService> services; + + public NetconfFacadeHoneycombBindingBroker(@Nonnull final DOMDataBroker domDataBrokerDependency, + @Nonnull final SchemaService schemaBiService) { + services = Maps.newHashMap(); + services.put(DOMDataBroker.class, domDataBrokerDependency); + // All services below are required to be present by Restconf northbound + services.put(SchemaService.class, schemaBiService); + services.put(DOMRpcService.class, EMPTY_DOM_RPC_SERVICE); + services.put(DOMMountPointService.class, EMPTY_DOM_MOUNT_SERVICE); + } + + @Override + public void close() throws Exception { + // NOOP + } + + @Override + public ConsumerSession registerConsumer(final Consumer consumer) { + final SimpleConsumerSession session = new SimpleConsumerSession(services); + consumer.onSessionInitiated(session); + return session; + } + + @Deprecated + @Override + public ConsumerSession registerConsumer(final Consumer consumer, final BundleContext bundleContext) { + throw new UnsupportedOperationException(); + } + + @Override + public ProviderSession registerProvider(final Provider provider) { + final SimpleProviderSession session = new SimpleProviderSession(services); + provider.onSessionInitiated(session); + return session; + } + + @Override + public ProviderSession registerProvider(final Provider provider, final BundleContext bundleContext) { + throw new UnsupportedOperationException(); + } + + @NotThreadSafe + private static class SimpleConsumerSession implements ConsumerSession { + private boolean closed; + private final Map<Class<? extends BrokerService>, BrokerService> services; + + private SimpleConsumerSession(final Map<Class<? extends BrokerService>, BrokerService> services) { + this.services = services; + } + + @Override + public boolean isClosed() { + return closed; + } + + @Override + public <T extends BrokerService> T getService(final Class<T> aClass) { + return (T)services.get(aClass); + } + + @Override + public void close() { + closed = true; + } + } + + @NotThreadSafe + private static class SimpleProviderSession implements ProviderSession { + private boolean closed; + private final Map<Class<? extends BrokerService>, BrokerService> services; + + private SimpleProviderSession(final Map<Class<? extends BrokerService>, BrokerService> services) { + this.services = services; + } + + @Override + public boolean isClosed() { + return closed; + } + + @Override + public <T extends BrokerService> T getService(final Class<T> aClass) { + return (T)services.get(aClass); + } + + @Override + public void close() { + closed = true; + } + } + + private static class EmptyDomRpcService implements DOMRpcService { + @Nonnull + @Override + public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(@Nonnull final SchemaPath schemaPath, + @Nullable final NormalizedNode<?, ?> normalizedNode) { + return Futures.<DOMRpcResult, DOMRpcException>immediateFailedCheckedFuture( + new DOMRpcImplementationNotAvailableException("RPCs not supported")); + } + + @Nonnull + @Override + public <T extends DOMRpcAvailabilityListener> ListenerRegistration<T> registerRpcListener(@Nonnull final T t) { + return new ListenerRegistration<T>() { + @Override + public void close() { + // Noop + } + + @Override + public T getInstance() { + return t; + } + }; + } + } + + private static class EmptyDomMountService implements DOMMountPointService { + @Override + public Optional<DOMMountPoint> getMountPoint(final YangInstanceIdentifier yangInstanceIdentifier) { + return Optional.absent(); + } + + @Override + public DOMMountPointBuilder createMountPoint(final YangInstanceIdentifier yangInstanceIdentifier) { + throw new UnsupportedOperationException("No mountpoint support"); + } + + @Override + public ListenerRegistration<MountProvisionListener> registerProvisionListener( + final MountProvisionListener mountProvisionListener) { + return new ListenerRegistration<MountProvisionListener>() { + @Override + public void close() { + // Noop + } + + @Override + public MountProvisionListener getInstance() { + return mountProvisionListener; + } + }; + } + } +} diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/V3poApiRequest.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/V3poApiRequest.java deleted file mode 100644 index 5416b3774..000000000 --- a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/V3poApiRequest.java +++ /dev/null @@ -1,454 +0,0 @@ -/* - * 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. - */ - -package io.fd.honeycomb.v3po.impl; - -import com.google.common.base.Preconditions; -import com.google.common.net.InetAddresses; -import com.google.common.primitives.Ints; -import com.google.common.util.concurrent.CheckedFuture; -import com.google.common.util.concurrent.Futures; -import java.math.BigInteger; -import java.net.InetAddress; -import javax.annotation.Nonnull; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.EthernetCsmacd; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.SoftwareLoopback; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfaceType; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.AdminStatus; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state._interface.Statistics; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state._interface.StatisticsBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface2; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface2Builder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.IpAddressOrigin; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Gauge64; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentation; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStateAugmentationBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStatisticsAugmentation; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceStatisticsAugmentationBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VxlanTunnel; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.Ethernet.Duplex; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.EthernetBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.L2Builder; -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.VxlanBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.l2.interconnection.BridgeBasedBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces.state._interface.l2.interconnection.XconnectBasedBuilder; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.openvpp.vppjapi.vppApi; -import org.openvpp.vppjapi.vppBridgeDomainDetails; -import org.openvpp.vppjapi.vppBridgeDomainInterfaceDetails; -import org.openvpp.vppjapi.vppIPv4Address; -import org.openvpp.vppjapi.vppIPv6Address; -import org.openvpp.vppjapi.vppInterfaceCounters; -import org.openvpp.vppjapi.vppInterfaceDetails; -import org.openvpp.vppjapi.vppVxlanTunnelDetails; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/* - * VPP API Class overriding interface details callback - */ -public class V3poApiRequest { - private static final Logger LOG = LoggerFactory.getLogger(V3poApiRequest.class); - private final VppPollOperDataImpl caller; - private final vppApi api; - - public V3poApiRequest(final vppApi api, final VppPollOperDataImpl vppPollOperData) { - this.api = api; - caller = vppPollOperData; - } - - private static InstanceIdentifier<Interface> getStateInterfaceIid(final String interfaceName) { - return InstanceIdentifier.create(InterfacesState.class).child(Interface.class, - new InterfaceKey(interfaceName)); - } - - private static InstanceIdentifier<Interface2> getStateInterfaceIpId(final InstanceIdentifier<Interface> iid) { - return iid.augmentation(Interface2.class); - } - - private static InstanceIdentifier<Statistics> getStateInterfaceStatsId(final InstanceIdentifier<Interface> iid) { - return iid.child(Statistics.class); - } - - private static Counter64 getCounter64(final long num) { - return new Counter64(BigInteger.valueOf(num)); - } - - private static Counter32 getCounter32(final long num) { - return new Counter32(num); - } - - private static Statistics buildInterfaceStatistics(final vppInterfaceCounters ifCounters) { - if (ifCounters == null) { - return null; - } - StatisticsBuilder statsBuilder = new StatisticsBuilder(); - - statsBuilder.setInBroadcastPkts(getCounter64(ifCounters.rxBroadcast)); - statsBuilder.setInDiscards(getCounter32(ifCounters.rxDiscard)); - statsBuilder.setInErrors(getCounter32(ifCounters.rxError)); - statsBuilder.setInMulticastPkts(getCounter64(ifCounters.rxMulticast)); - statsBuilder.setInOctets(getCounter64(ifCounters.rxOctets)); - statsBuilder.setInUnicastPkts(getCounter64(ifCounters.rxUnicast)); - statsBuilder.setInUnknownProtos(getCounter32(ifCounters.rxUnknownProto)); - - statsBuilder.setOutBroadcastPkts(getCounter64(ifCounters.txBroadcast)); - statsBuilder.setOutDiscards(getCounter32(ifCounters.txDiscard)); - statsBuilder.setOutErrors(getCounter32(ifCounters.txError)); - statsBuilder.setOutMulticastPkts(getCounter64(ifCounters.txMulticast)); - statsBuilder.setOutOctets(getCounter64(ifCounters.txOctets)); - statsBuilder.setOutUnicastPkts(getCounter64(ifCounters.txUnicast)); - - VppInterfaceStatisticsAugmentationBuilder statsAugBuilder = - new VppInterfaceStatisticsAugmentationBuilder(); - statsAugBuilder.setInErrorsMiss(getCounter64(ifCounters.rxMiss)); - statsAugBuilder.setInErrorsNoBuf(getCounter64(ifCounters.rxFifoFull)); // FIXME? Is this right? - statsAugBuilder.setOutDiscardsFifoFull(getCounter64(ifCounters.txFifoFull)); - - statsBuilder.addAugmentation(VppInterfaceStatisticsAugmentation.class, - statsAugBuilder.build()); - - return statsBuilder.build(); - } - - private static String getMacAddress(final byte[] mac) { - StringBuilder sb = new StringBuilder(18); - for (byte b : mac) { - if (sb.length() > 0) { - sb.append(':'); - } - sb.append(String.format("%02x", b)); - } - return sb.toString(); - } - - private static final Gauge64 vppSpeed0 = new Gauge64(BigInteger.ZERO); - private static final Gauge64 vppSpeed1 = new Gauge64(BigInteger.valueOf(10 * 1000000)); - private static final Gauge64 vppSpeed2 = new Gauge64(BigInteger.valueOf(100 * 1000000)); - private static final Gauge64 vppSpeed4 = new Gauge64(BigInteger.valueOf(1000 * 1000000)); - private static final Gauge64 vppSpeed8 = new Gauge64(BigInteger.valueOf(10000L * 1000000)); - private static final Gauge64 vppSpeed16 = new Gauge64(BigInteger.valueOf(40000L * 1000000)); - private static final Gauge64 vppSpeed32 = new Gauge64(BigInteger.valueOf(100000L * 1000000)); - - private static Gauge64 getSpeed(final byte vppSpeed) { - switch (vppSpeed) { - case 1: return vppSpeed1; - case 2: return vppSpeed2; - case 4: return vppSpeed4; - case 8: return vppSpeed8; - case 16: return vppSpeed16; - case 32: return vppSpeed32; - default: return vppSpeed0; - } - } - - private static String ipv4IntToString(final int ip) { - return InetAddresses.fromInteger(ip).getHostAddress(); - } - - private Interface buildStateInterface(final int ifIndex, - @Nonnull final String interfaceName, - final int supIfIndex, - final byte[] physAddr, - final byte adminUp, final byte linkUp, - final byte linkDuplex, final byte linkSpeed, - final int subId, final byte subDot1ad, - final byte subNumberOfTags, - final int subOuterVlanId, - final int subInnerVlanId, - final byte subExactMatch, - final byte subDefault, - final byte subOuterVlanIdAny, - final byte subInnerVlanIdAny, - final int vtrOp, final int vtrPushDot1q, - final int vtrTag1, final int vtrTag2, - final Statistics stats) { - Preconditions.checkNotNull(interfaceName, "interfaceName should not be null"); - InterfaceBuilder ifBuilder = new InterfaceBuilder(); - Class<? extends InterfaceType> ifType; - - // FIXME: missing types for virtualethernet, subinterface, tap interface etc - if (interfaceName.startsWith("loop")) { - ifType = SoftwareLoopback.class; - } else if (interfaceName.startsWith("vxlan_tunnel")) { - ifType = VxlanTunnel.class; - } else { - ifType = EthernetCsmacd.class; - } - ifBuilder.setName(interfaceName) - .setType(ifType) - .setAdminStatus((adminUp == 0 ? AdminStatus.Down : AdminStatus.Up)) - .setOperStatus((linkUp == 0 ? OperStatus.Down : OperStatus.Up)); -/* - DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> builder = ImmutableNodes.mapEntryBuilder() - .withNodeIdentifier(new NodeIdentifierWithPredicates(Interface.QNAME, NAME_QNAME, interfaceName)); - builder.withChild(ImmutableNodes.leafNode(IF_TYPE, SoftwareLoopback.QNAME))*/ - - // subinterface? - if (ifIndex != supIfIndex) { - // TODO: get name and set - } - - if (physAddr != null) { - ifBuilder.setPhysAddress(new PhysAddress(getMacAddress(physAddr))); - } - ifBuilder.setSpeed(getSpeed(linkSpeed)); - - if (stats != null) { - ifBuilder.setStatistics(stats); - } - int bdId = api.bridgeDomainIdFromInterfaceName(interfaceName); - vppBridgeDomainDetails bd = (bdId != -1 ? api.getBridgeDomainDetails(bdId) : null); - - String bdName = null; - short splitHorizonGroup = 0; - boolean bvi = false; - - if (bd != null) { - bdName = bd.name; - for (vppBridgeDomainInterfaceDetails bdIf : bd.interfaces) { - if (!interfaceName.equals(bdIf.interfaceName)) { - continue; - } - if (interfaceName.equals(bd.bviInterfaceName)) { - bvi = true; - } - splitHorizonGroup = bdIf.splitHorizonGroup; - } - } - - VppInterfaceStateAugmentationBuilder vppIfStateAugBuilder = - new VppInterfaceStateAugmentationBuilder(); - - vppIfStateAugBuilder.setDescription(api.getInterfaceDescription(interfaceName)); - - setStateInterfaceL2(vppIfStateAugBuilder, bdId != -1, false, null, - bdName, splitHorizonGroup, bvi); - - if (EthernetCsmacd.class == ifType) { - setStateInterfaceEthernet(vppIfStateAugBuilder, linkDuplex == 2, - "ACME Inc.", 1234); - } - - vppVxlanTunnelDetails[] vxlanDet = api.vxlanTunnelDump(ifIndex); - if (null != vxlanDet && vxlanDet.length >= 1) { - setStateInterfaceVxlan(vppIfStateAugBuilder, vxlanDet[0].srcAddress, - vxlanDet[0].dstAddress, vxlanDet[0].vni, - vxlanDet[0].encapVrfId); - } - - ifBuilder.addAugmentation(VppInterfaceStateAugmentation.class, - vppIfStateAugBuilder.build()); - - InterfaceStateIpv4Builder ipv4Builder = new InterfaceStateIpv4Builder(); -// TODO ipv4Builder.setMtu(1234); - - InetAddress addr = null; - - vppIPv4Address[] ipv4Addrs = api.ipv4AddressDump(interfaceName); - if (ipv4Addrs != null) { - for (vppIPv4Address vppAddr : ipv4Addrs) { - if (null == vppAddr) { - LOG.error("ipv4 address structure in null"); - continue; - } - - // FIXME: vppIPv4Address and vppIPv6 address can be the same if both will use - // byte array for ip - byte[] bytes = Ints.toByteArray(vppAddr.ip); - try { - addr = InetAddress.getByAddress(bytes); - } catch (java.net.UnknownHostException e) { - e.printStackTrace(); - continue; - } - - ipv4Builder.addAddress(addr.getHostAddress(), vppAddr.prefixLength, IpAddressOrigin.Static); - } - } - - InterfaceStateIpv6Builder ipv6Builder = new InterfaceStateIpv6Builder(); -// TODO ipv6Builder.setMtu(1234); - - vppIPv6Address[] ipv6Addrs = api.ipv6AddressDump(interfaceName); - if (ipv6Addrs != null) { - for (vppIPv6Address vppAddr : ipv6Addrs) { - if (null == vppAddr) { - LOG.error("ipv6 address structure in null"); - continue; - } - - byte[] bytes = vppAddr.ip; - try { - addr = InetAddress.getByAddress(bytes); - } catch (java.net.UnknownHostException e) { - e.printStackTrace(); - continue; - } - - ipv6Builder.addAddress(addr.getHostAddress(), vppAddr.prefixLength, IpAddressOrigin.Static); - } - } - Interface2Builder ipBuilder = new Interface2Builder(); - - ipBuilder.setIpv4(ipv4Builder.build()); - ipBuilder.setIpv6(ipv6Builder.build()); - - ifBuilder.addAugmentation(Interface2.class, ipBuilder.build()); - - return ifBuilder.build(); - } - - private static void setStateInterfaceL2( - final VppInterfaceStateAugmentationBuilder augBuilder, - final boolean isL2BridgeBased, final boolean isXconnect, - final String xconnectOutgoingInterface, - final String bdName, final short splitHorizonGroup, final boolean bvi) { - - L2Builder l2Builder = new L2Builder(); - - if (isXconnect) { - l2Builder.setInterconnection( - new XconnectBasedBuilder() - .setXconnectOutgoingInterface(xconnectOutgoingInterface) - .build()); - } else if (isL2BridgeBased) { - l2Builder.setInterconnection( - new BridgeBasedBuilder() - .setBridgeDomain(bdName) - .setSplitHorizonGroup(splitHorizonGroup) - .setBridgedVirtualInterface(bvi) - .build()); - } - - augBuilder.setL2(l2Builder.build()); - } - - private static void setStateInterfaceEthernet( - final VppInterfaceStateAugmentationBuilder augBuilder, - final boolean isFullDuplex, final String manufacturerDesc, final Integer mtu) { - - EthernetBuilder ethBuilder = new EthernetBuilder(); - ethBuilder.setDuplex((isFullDuplex ? Duplex.Full : Duplex.Half)) - .setManufacturerDescription(manufacturerDesc) - .setMtu(mtu); - - augBuilder.setEthernet(ethBuilder.build()); - } - - private static void setStateInterfaceVxlan( - final VppInterfaceStateAugmentationBuilder augBuilder, final int srcAddress, - final int dstAddress, final int vni, final int encapVrfId) { - - String srcAddressStr = ipv4IntToString(srcAddress); - String dstAddressStr = ipv4IntToString(dstAddress); - - VxlanBuilder vxlanBuilder = new VxlanBuilder(); - Vxlan vxlan = vxlanBuilder - .setSrc(new Ipv4AddressNoZone(srcAddressStr)) - .setDst(new Ipv4AddressNoZone(dstAddressStr)) - .setVni((long)vni) - .setEncapVrfId((long)encapVrfId) - .build(); - - augBuilder.setVxlan(vxlan); - } - - private void writeToIfState(final InstanceIdentifier<Interface> iid, - final Interface intf) { - DataBroker db = caller.getDataBroker(); - WriteTransaction transaction = db.newWriteOnlyTransaction(); - // TODO: how to delete existing interfaces that disappeared? (reset it before each dumpInterfaces call?) - - /*LOG.info("VPPOPER-INFO: Adding interface " + intf.getName() - + " to oper DataStore.");*/ - transaction.put(LogicalDatastoreType.OPERATIONAL, iid, intf); - - CheckedFuture<Void, TransactionCommitFailedException> future = - transaction.submit(); - Futures.addCallback(future, new LoggingFuturesCallBack<Void>( - "VPPOPER-WARNING: Failed to write " - + "interface to ietf-interfaces state", LOG)); - } - - private void processInterfaces(final vppInterfaceDetails[] ifaces) { - for (vppInterfaceDetails swIf : ifaces) { - interfaceDetails(swIf); - } - } - - /** - * TODO-ADD-JAVADOC. - */ - public void swInterfaceDumpAll() { - vppInterfaceDetails[] ifaces; - - ifaces = api.swInterfaceDump((byte) 1, "Ether".getBytes()); - processInterfaces(ifaces); - - ifaces = api.swInterfaceDump((byte) 1, "lo".getBytes()); - processInterfaces(ifaces); - - ifaces = api.swInterfaceDump((byte) 1, "vxlan".getBytes()); - processInterfaces(ifaces); - - ifaces = api.swInterfaceDump((byte) 1, "l2tpv3_tunnel".getBytes()); - processInterfaces(ifaces); - - ifaces = api.swInterfaceDump((byte) 1, "tap".getBytes()); - processInterfaces(ifaces); - } - - private void interfaceDetails(final vppInterfaceDetails swIf) { - /*LOG.info("Got interface {} (idx: {}) adminUp: {} linkUp: {} duplex: {} speed: {} subId: {}", - swIf.interfaceName, swIf.ifIndex, swIf.adminUp, swIf.linkUp, swIf.linkDuplex, swIf.linkSpeed, swIf.subId);*/ - - vppInterfaceCounters ifCounters = api.getInterfaceCounters(swIf.ifIndex); - - InstanceIdentifier<Interface> iid = getStateInterfaceIid(swIf.interfaceName); - - Statistics stats = buildInterfaceStatistics(ifCounters); - - Interface intf = buildStateInterface(swIf.ifIndex, swIf.interfaceName, - swIf.supIfIndex, swIf.physAddr, - swIf.adminUp, swIf.linkUp, - swIf.linkDuplex, swIf.linkSpeed, - swIf.subId, swIf.subDot1ad, - swIf.subNumberOfTags, - swIf.subOuterVlanId, - swIf.subInnerVlanId, - swIf.subExactMatch, swIf.subDefault, - swIf.subOuterVlanIdAny, - swIf.subInnerVlanIdAny, - swIf.vtrOp, swIf.vtrPushDot1q, - swIf.vtrTag1, swIf.vtrTag2, stats); - writeToIfState(iid, intf); - } -} diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/V3poProvider.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/V3poProvider.java deleted file mode 100644 index 5dcf586fa..000000000 --- a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/V3poProvider.java +++ /dev/null @@ -1,291 +0,0 @@ -/* - * 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. - */ - -package io.fd.honeycomb.v3po.impl; - -import com.google.common.base.Preconditions; -import com.google.common.collect.Lists; -import com.google.common.util.concurrent.CheckedFuture; -import com.google.common.util.concurrent.Futures; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Timer; -import javax.annotation.Nonnull; -import javax.annotation.concurrent.NotThreadSafe; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; -import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration; -import org.opendaylight.controller.sal.binding.api.BindingAwareProvider; -import org.opendaylight.controller.sal.core.api.Broker; -import org.opendaylight.controller.sal.core.api.BrokerService; -import org.opendaylight.controller.sal.core.api.Consumer; -import org.opendaylight.controller.sal.core.api.Provider; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.EthernetCsmacd; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.SoftwareLoopback; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfaceType; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesStateBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.V3poService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.Vpp; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VxlanTunnel; -import org.opendaylight.yangtools.binding.data.codec.api.BindingNormalizedNodeSerializer; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.openvpp.vppjapi.vppApi; -import org.openvpp.vppjapi.vppInterfaceDetails; -import org.osgi.framework.BundleContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class V3poProvider implements BindingAwareProvider, AutoCloseable, Broker { - - private static final Logger LOG = LoggerFactory.getLogger(V3poProvider.class); - private final Broker domBroker; - private final BindingNormalizedNodeSerializer serializer; - private final DOMDataBroker domDataBroker; - private RpcRegistration<V3poService> v3poService; - private VppIetfInterfaceListener vppInterfaceListener; - private VppBridgeDomainListener vppBridgeDomainListener; - private vppApi api; - private DataBroker db; - VppPollOperDataImpl vppPollOperData; - private VppDataBrokerInitializationProvider vppDataBrokerInitializationProvider; - - public V3poProvider(@Nonnull final Broker domBroker, final vppApi vppJapi, - @Nonnull final BindingNormalizedNodeSerializer serializer, - @Nonnull final DOMDataBroker domDataBroker) { - api = vppJapi; - this.domBroker = Preconditions.checkNotNull(domBroker, "domBroker should not be null"); - this.serializer = Preconditions.checkNotNull(serializer, "serializer should not be null"); - this.domDataBroker = Preconditions.checkNotNull(domDataBroker, "domDataBroker should not be null"); - } - - private void initializeVppConfig() { - - WriteTransaction transaction = db.newWriteOnlyTransaction(); - InstanceIdentifier<Vpp> viid = InstanceIdentifier.create(Vpp.class); - Vpp vpp = new VppBuilder().build(); - // FIXME uncomment after ODL bug-5382 is fixed - // transaction.put(LogicalDatastoreType.CONFIGURATION, viid, vpp); - CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit(); - Futures.addCallback(future, new - LoggingFuturesCallBack<>("VPPCFG-WARNING: Failed to create Vpp " - + "configuration db.", - LOG)); - vppBridgeDomainListener = new VppBridgeDomainListener(db, api); - - LOG.info("VPPCFG-INFO: Preparing to initialize the IETF Interface " + "list configuration db."); - transaction = db.newWriteOnlyTransaction(); - - // FIXME this is minimal and we need to sync the entire configuration - // FIXME remove from here and make this specific for interface customizers - syncInterfaces(transaction, api); - - future = transaction.submit(); - Futures.addCallback(future, new - LoggingFuturesCallBack<>("VPPCFG-WARNING: Failed to create IETF " - + "Interface list configuration db.", - LOG)); - vppInterfaceListener = new VppIetfInterfaceListener(db, api); - - } - - private static final Map<String, Class<? extends InterfaceType>> IFC_TYPES = - new HashMap<String, Class<? extends InterfaceType>>() {{ - put("vxlan", VxlanTunnel.class); - put("lo", SoftwareLoopback.class); - put("Ether", EthernetCsmacd.class); - // TODO missing types below - put("l2tpv3_tunnel", EthernetCsmacd.class); - put("tap", EthernetCsmacd.class); - }}; - - /** - * Dump all interfaces from VPP and populate config datastore to sync initial state (interfaces) - * Only the mandatory leaves are stored in config datastore - */ - private void syncInterfaces(final WriteTransaction transaction, final vppApi api) { - LOG.info("Starting interface configuration sync"); - final List<Interface> ifcs = Lists.newArrayList(); - for (Map.Entry<String, Class<? extends InterfaceType>> ifcType : IFC_TYPES.entrySet()) { - - for (vppInterfaceDetails vppIfc : api.swInterfaceDump(((byte) 1), ifcType.getKey().getBytes())) { - ifcs.add(new InterfaceBuilder() - .setName(vppIfc.interfaceName) - .setKey(new InterfaceKey(vppIfc.interfaceName)) - .setEnabled(vppIfc.adminUp == 1) - .setType(ifcType.getValue()) - .build()); - } - } - - InstanceIdentifier<Interfaces> iid = InstanceIdentifier.create(Interfaces.class); - transaction.put(LogicalDatastoreType.CONFIGURATION, iid, new InterfacesBuilder().setInterface(ifcs).build()); - LOG.info("Interface configuration sync ended with following interfaces: {}", ifcs); - } - - /* operational data */ - - private void initVppOperational() { - /* - * List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf. - * interfaces.rev140508.interfaces.state.Interface> ifaces = new - * ArrayList<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang. - * ietf.interfaces.rev140508.interfaces.state.Interface>(); - */ - LOG.info("VPPOPER-INFO: Preparing to initialize the IETF Interface " + "state list operational db."); - InterfacesState ifsState = new InterfacesStateBuilder().build(); - WriteTransaction tx = db.newWriteOnlyTransaction(); - InstanceIdentifier<InterfacesState> isid = InstanceIdentifier.builder(InterfacesState.class).build(); - tx.put(LogicalDatastoreType.OPERATIONAL, isid, ifsState); - Futures.addCallback(tx.submit(), new LoggingFuturesCallBack<>( - "VPPOPER-WARNING: Failed to create IETF " + "Interface state list operational db.", LOG)); - } - - private void startOperationalUpdateTimer() { - Timer timer = new Timer(); - - // fire task after 1 second and then repeat each 10 seconds -// timer.scheduleAtFixedRate(new TimerTask() { -// @Override -// public void run() { -// vppPollOperData.updateOperational(); -// } -// }, 1000, 10000); - } - - @Override - public void onSessionInitiated(final ProviderContext session) { - LOG.info("VPP-INFO: V3poProvider Session Initiated"); - - db = session.getSALService(DataBroker.class); - initializeVppConfig(); - initVppOperational(); - - vppPollOperData = new VppPollOperDataImpl(api, db); - v3poService = session.addRpcImplementation(V3poService.class, - vppPollOperData); - startOperationalUpdateTimer(); - - // TODO make configurable: - vppDataBrokerInitializationProvider = new VppDataBrokerInitializationProvider(db, serializer, domDataBroker); - // TODO pull the registration into Module - domBroker.registerProvider(vppDataBrokerInitializationProvider); - } - - @Override - public void close() throws Exception { - LOG.info("VPP-INFO: V3poProvider Closed"); - if (v3poService != null) { - v3poService.close(); - } - if (vppDataBrokerInitializationProvider != null) { - vppDataBrokerInitializationProvider.close(); - } - } - - // DomBroker functionality below. Should go out of here. TODO do that when cleaning up this provider - - @Override - public ConsumerSession registerConsumer(final Consumer consumer) { - final SimpleConsumerSession session = new SimpleConsumerSession( - Collections.<Class<? extends BrokerService>, BrokerService>singletonMap(DOMDataBroker.class, - vppDataBrokerInitializationProvider.getBroker().get())); - consumer.onSessionInitiated(session); - return session; - } - - @Deprecated - @Override - public ConsumerSession registerConsumer(final Consumer consumer, final BundleContext bundleContext) { - throw new UnsupportedOperationException(); - } - - @Override - public ProviderSession registerProvider(final Provider provider) { - final SimpleProviderSession session = new SimpleProviderSession( - Collections.<Class<? extends BrokerService>, BrokerService>singletonMap(DOMDataBroker.class, - vppDataBrokerInitializationProvider.getBroker().get())); - provider.onSessionInitiated(session); - return session; - } - - @Override - public ProviderSession registerProvider(final Provider provider, final BundleContext bundleContext) { - throw new UnsupportedOperationException(); - } - - @NotThreadSafe - private static class SimpleConsumerSession implements ConsumerSession { - private boolean closed; - private final Map<Class<? extends BrokerService>, BrokerService> services; - - private SimpleConsumerSession(final Map<Class<? extends BrokerService>, BrokerService> services) { - this.services = services; - } - - @Override - public boolean isClosed() { - return closed; - } - - @Override - public <T extends BrokerService> T getService(final Class<T> aClass) { - return (T)services.get(aClass); - } - - @Override - public void close() { - closed = true; - } - } - - @NotThreadSafe - private static class SimpleProviderSession implements ProviderSession { - private boolean closed; - private final Map<Class<? extends BrokerService>, BrokerService> services; - - private SimpleProviderSession(final Map<Class<? extends BrokerService>, BrokerService> services) { - this.services = services; - } - - @Override - public boolean isClosed() { - return closed; - } - - @Override - public <T extends BrokerService> T getService(final Class<T> aClass) { - return (T)services.get(aClass); - } - - @Override - public void close() { - closed = true; - } - } -} diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/VppBridgeDomainListener.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/VppBridgeDomainListener.java deleted file mode 100644 index 94d8df7c7..000000000 --- a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/VppBridgeDomainListener.java +++ /dev/null @@ -1,217 +0,0 @@ -/* - * 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. - */ - -package io.fd.honeycomb.v3po.impl; - -import java.util.Collection; - -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.DataObjectModification; -import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener; -import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier; -import org.opendaylight.controller.md.sal.binding.api.DataTreeModification; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.Vpp; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.BridgeDomains; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomain; -import org.opendaylight.yangtools.concepts.ListenerRegistration; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.openvpp.vppjapi.vppApi; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class VppBridgeDomainListener implements DataTreeChangeListener<BridgeDomain>, - AutoCloseable { - private static final Logger LOG = - LoggerFactory.getLogger(VppBridgeDomainListener.class); - private ListenerRegistration<VppBridgeDomainListener> registration; - private DataBroker db; - private vppApi api; - - private enum DataChangeType { - CREATE, UPDATE, DELETE - } - - /** - * TODO-ADD-JAVADOC. - */ - public VppBridgeDomainListener(DataBroker db, vppApi api) { - this.db = db; - this.api = api; - InstanceIdentifier<BridgeDomain> iid = InstanceIdentifier - .create(Vpp.class) - .child(BridgeDomains.class) - .child(BridgeDomain.class); - LOG.info("VPPCFG-INFO: Register listener for VPP Bridge Domain data changes"); - - DataTreeIdentifier<BridgeDomain> path = - new DataTreeIdentifier<BridgeDomain>(LogicalDatastoreType.CONFIGURATION, iid); - registration = this.db.registerDataTreeChangeListener(path, this); - } - - @Override - public void onDataTreeChanged(Collection<DataTreeModification<BridgeDomain>> changes) { - - for (DataTreeModification<BridgeDomain> change: changes) { - InstanceIdentifier<BridgeDomain> iid = change.getRootPath().getRootIdentifier(); - DataObjectModification<BridgeDomain> changeDiff = change.getRootNode(); - - switch (changeDiff.getModificationType()) { - case SUBTREE_MODIFIED: - case WRITE: - // create, modify or replace - createOrUpdateBridgeDomain(changeDiff); - break; - case DELETE: - deleteBridgeDomain(changeDiff); - break; - default: - LOG.info("Unsupported change type {} for {}", - changeDiff.getModificationType(), iid); - } - } - } - - // handles only CREATE and UPDATE calls - private void vppSetBridgeDomain(BridgeDomain bridgeDomain, DataChangeType type, - BridgeDomain originalBridgeDomain) { - int rv = -77; - int cnt = 0; - String bdName = bridgeDomain.getName(); - int bdId = api.findOrAddBridgeDomainId(bdName); - - LOG.info("VPPCFG-INFO: {} <bridgeDomain>", type); - LOG.info("VPPCFG-INFO: Name: " + bdName); - LOG.info("VPPCFG-INFO: Flood: {} ", bridgeDomain.isFlood()); - LOG.info("VPPCFG-INFO: Forward: {} ", bridgeDomain.isForward()); - LOG.info("VPPCFG-INFO: Learn: {} ", bridgeDomain.isLearn()); - LOG.info("VPPCFG-INFO: UnknownUnicastFlood: {} ", - bridgeDomain.isUnknownUnicastFlood()); - LOG.info("VPPCFG-INFO: ArpTermination: {} ", - bridgeDomain.isArpTermination()); - LOG.info("VPPCFG-INFO: {} </bridgeDomain>", type); - - switch (type) { - case CREATE: - case UPDATE: - byte flood = bridgeDomain.isFlood() ? (byte) 1 : (byte) 0; - byte forward = bridgeDomain.isForward() ? (byte) 1 : (byte) 0; - byte learn = bridgeDomain.isLearn() ? (byte) 1 : (byte) 0; - byte uuf = bridgeDomain.isUnknownUnicastFlood() ? (byte) 1 : (byte) 0; - byte arpTerm = bridgeDomain.isArpTermination() ? (byte) 1 : (byte) 0; - if ((bdId == -1) || (bdId == 0)) { - LOG.warn("VPPCFG-WARNING: Bridge Domain create/lookup failed" - + " (bdId = {})! Ignoring vppSetBridgeDomain request {}", - bdId, type); - return; - } else { - int ctxId = api.bridgeDomainAddDel(bdId, flood, forward, - learn, uuf, arpTerm, - (byte) 1 /* isAdd */); - LOG.info("VPPCFG-INFO: {} api.bridgeDomainAddDel({} ({})) " - + "ctxId = {}", type, bdName, bdId, ctxId); - while (rv == -77) { - rv = api.getRetval(ctxId, 1 /* release */); - cnt++; - } - LOG.info("VPPCFG-INFO: {} api.bridgeDomainAddDel({} ({})) " - + "retval {} after {} tries.", - type, bdName, bdId, rv, cnt); - - if (rv < 0) { - LOG.warn("VPPCFG-WARNING: {} api.bridgeDomainAddDel({}" - + " ({})) failed: retval {}!", - type, bdName, bdId, rv); - /* DAW-FIXME: throw exception on failure? */ - } - } - break; - default: - LOG.warn("VPPCFG-WARNING: Unknown DataChangeType {}! " - + "Ignoring vppSetBridgeDomain request", type); - return; - } - bdId = api.bridgeDomainIdFromName(bdName); - LOG.info("VPPCFG-INFO: {} api.bridgeDomainIdFromName({}) = {}", - type, bdName, bdId); - } - - private void createOrUpdateBridgeDomain(DataObjectModification<BridgeDomain> changeDiff) { - if (changeDiff.getDataBefore() == null) { - vppSetBridgeDomain(changeDiff.getDataAfter(), - DataChangeType.CREATE, null); - } else { - vppSetBridgeDomain(changeDiff.getDataAfter(), - DataChangeType.UPDATE, - changeDiff.getDataBefore()); - } - } - - // handles DELETE calls - private void deleteBridgeDomain(DataObjectModification<BridgeDomain> changeDiff) { - DataChangeType type = DataChangeType.DELETE; - BridgeDomain bridgeDomain = changeDiff.getDataBefore(); - String bdName = bridgeDomain.getName(); - int rv = -77; - int cnt = 0; - - LOG.info("VPPCFG-INFO: {} <bridgeDomain>", type); - LOG.info("VPPCFG-INFO: Name: " + bdName); - LOG.info("VPPCFG-INFO: Flood: {} ", bridgeDomain.isFlood()); - LOG.info("VPPCFG-INFO: Forward: {} ", bridgeDomain.isForward()); - LOG.info("VPPCFG-INFO: Learn: {} ", bridgeDomain.isLearn()); - LOG.info("VPPCFG-INFO: UnknownUnicastFlood: {} ", - bridgeDomain.isUnknownUnicastFlood()); - LOG.info("VPPCFG-INFO: ArpTermination: {} ", - bridgeDomain.isArpTermination()); - LOG.info("VPPCFG-INFO: {} </bridgeDomain>", type); - - int bdId = api.findOrAddBridgeDomainId(bdName); - if ((bdId == -1) || (bdId == 0)) { - LOG.warn("VPPCFG-WARNING: Unknown Bridge Domain {} " - + " (bdId = {})! Ignoring vppSetBridgeDomain request {}", - bdName, bdId, type); - return; - } else { - int ctxId = api.bridgeDomainAddDel(bdId, (byte) 0 /* flood */, - (byte) 0 /* forward */, - (byte) 0 /* learn */, - (byte) 0 /* uuf */, - (byte) 0 /* arpTerm */, - (byte) 0 /* isAdd */); - LOG.info("VPPCFG-INFO: {} api.bridgeDomainAddDel({} ({})) " - + "ctxId = {}", type, bdName, bdId, ctxId); - while (rv == -77) { - rv = api.getRetval(ctxId, 1 /* release */); - cnt++; - } - LOG.info("VPPCFG-INFO: {} api.bridgeDomainAddDel({} ({})) " - + "retval {} after {} tries.", - type, bdName, bdId, rv, cnt); - - if (rv < 0) { - LOG.warn("VPPCFG-WARNING: {} api.bridgeDomainAddDel({} ({}))" - + " failed: retval {}!", type, bdName, bdId, rv); - /* DAW-FIXME: throw exception on failure? */ - } - } - } - - @Override - public void close() throws Exception { - registration.close(); - } -} diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/VppDataBrokerInitializationProvider.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/VppDataBrokerInitializationProvider.java deleted file mode 100644 index c1d22f9da..000000000 --- a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/VppDataBrokerInitializationProvider.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright (c) 2016 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. - */ - -package io.fd.honeycomb.v3po.impl; - -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Optional; -import com.google.common.base.Preconditions; -import java.util.Collection; -import java.util.Collections; -import javax.annotation.Nonnull; -import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; -import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; -import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; -import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; -import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint; -import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService; -import org.opendaylight.controller.sal.core.api.Broker; -import org.opendaylight.controller.sal.core.api.Provider; -import org.opendaylight.controller.sal.core.api.model.SchemaService; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey; -import org.opendaylight.yangtools.binding.data.codec.api.BindingNormalizedNodeSerializer; -import org.opendaylight.yangtools.concepts.ObjectRegistration; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Creates VppDataBroker which uses DataTree instead of DataStore internally in order to obtain better control over the - * data processing in Honeycomb agent - */ -public final class VppDataBrokerInitializationProvider implements Provider, AutoCloseable { - - private static final Logger LOG = LoggerFactory.getLogger(VppDataBrokerInitializationProvider.class); - - private final TopologyId VPP_TOPOLOGY_ID = TopologyId.getDefaultInstance("vpp-topology"); - private final NodeId VPP_TOPOLOGY_NODE_ID = NodeId.getDefaultInstance("vpp"); - private final org.opendaylight.controller.md.sal.binding.api.DataBroker bindingBroker; - private final InstanceIdentifier<Node> mountPointPath; - private final BindingNormalizedNodeSerializer serializer; - private ObjectRegistration<DOMMountPoint> mountPointRegistration; - private final DOMDataBroker domDataBroker; - - public VppDataBrokerInitializationProvider( - @Nonnull final org.opendaylight.controller.md.sal.binding.api.DataBroker bindingBroker, - @Nonnull final BindingNormalizedNodeSerializer serializer, - @Nonnull final DOMDataBroker domDataBroker) { - this.bindingBroker = checkNotNull(bindingBroker, "bindingBroker should not be null"); - this.serializer = checkNotNull(serializer, "serializer should not be null"); - this.domDataBroker = checkNotNull(domDataBroker, "domDataBroker should not be null"); - this.mountPointPath = getMountPointPath(); - } - - // TODO make configurable - private InstanceIdentifier<Node> getMountPointPath() { - final InstanceIdentifier<NetworkTopology> networkTopology = - InstanceIdentifier.builder(NetworkTopology.class).build(); - final KeyedInstanceIdentifier<Topology, TopologyKey> topology = - networkTopology.child(Topology.class, new TopologyKey(VPP_TOPOLOGY_ID)); - return topology.child(Node.class, new NodeKey(VPP_TOPOLOGY_NODE_ID)); - } - - @Override - public void onSessionInitiated(final Broker.ProviderSession providerSession) { - LOG.info("Session initialized, providerSession={}", providerSession); - Preconditions.checkState(!isMountPointRegistered(), "Mount point is already registered"); - - final DOMMountPointService mountPointService = providerSession.getService(DOMMountPointService.class); - final SchemaService schemaService = providerSession.getService(SchemaService.class); - - final SchemaContext globalContext = schemaService.getGlobalContext(); - final YangInstanceIdentifier path = serializer.toYangInstanceIdentifier(mountPointPath); - - final DOMMountPointService.DOMMountPointBuilder mountPointBuilder = mountPointService.createMountPoint(path); - mountPointBuilder.addInitialSchemaContext(globalContext); - - mountPointBuilder.addService(DOMDataBroker.class, domDataBroker); - - mountPointRegistration = mountPointBuilder.register(); - final DOMMountPoint mountPoint = mountPointRegistration.getInstance(); - LOG.debug("Created mountPoint: identifier={}, schemaContext={}", mountPoint.getIdentifier(), - mountPoint.getSchemaContext()); - - createMountPointPlaceholder(); - } - - @Override - public Collection<ProviderFunctionality> getProviderFunctionality() { - return Collections.EMPTY_LIST; - } - - private boolean isMountPointRegistered() { - final ReadOnlyTransaction readTx = bindingBroker.newReadOnlyTransaction(); - try { - final Optional<Node> cfgPlaceholder = - readTx.read(LogicalDatastoreType.CONFIGURATION, mountPointPath).checkedGet(); - final Optional<Node> operPlaceholder = - readTx.read(LogicalDatastoreType.OPERATIONAL, mountPointPath).checkedGet(); - return cfgPlaceholder.isPresent() || operPlaceholder.isPresent(); - } catch (ReadFailedException e) { - throw new IllegalStateException("Failed to read mountpoint placeholder data", e); - } - } - - /** - * Writes placeholder data into MD-SAL's global datastore to indicate the presence of VPP mountpoint. - */ - private void createMountPointPlaceholder() { - final NodeBuilder nodeBuilder = new NodeBuilder(); - nodeBuilder.setKey(new NodeKey(VPP_TOPOLOGY_NODE_ID)); - final Node node = nodeBuilder.build(); - - final WriteTransaction writeTx = bindingBroker.newWriteOnlyTransaction(); - writeTx.merge(LogicalDatastoreType.CONFIGURATION, mountPointPath, node, true); - writeTx.merge(LogicalDatastoreType.OPERATIONAL, mountPointPath, node, true); - - try { - writeTx.submit().checkedGet(); - } catch (TransactionCommitFailedException e) { - throw new IllegalStateException("Failed to create mountpoint placeholder", e); - } - } - - public Optional<DOMDataBroker> getBroker() { - return Optional.fromNullable(domDataBroker); - } - - @Override - public void close() throws Exception { - if (mountPointRegistration != null) { - mountPointRegistration.close(); - } - - // remove MD-SAL placeholder data for VPP mount point: - final WriteTransaction rwTx = bindingBroker.newWriteOnlyTransaction(); - // does not fail if data is not present: - rwTx.delete(LogicalDatastoreType.CONFIGURATION, mountPointPath); - rwTx.delete(LogicalDatastoreType.OPERATIONAL, mountPointPath); - try { - rwTx.submit().checkedGet(); - } catch (TransactionCommitFailedException e) { - throw new IllegalStateException("Failed to remove mountpoint's placeholder from MD-SAL's global datastore", - e); - } - } -} diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/VppIetfInterfaceListener.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/VppIetfInterfaceListener.java deleted file mode 100644 index c45fe1fe1..000000000 --- a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/VppIetfInterfaceListener.java +++ /dev/null @@ -1,554 +0,0 @@ -/* - * 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. - */ - -package io.fd.honeycomb.v3po.impl; - -import com.google.common.base.Splitter; -import java.util.Collection; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.DataObjectModification; -import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener; -import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier; -import org.opendaylight.controller.md.sal.binding.api.DataTreeModification; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.EthernetCsmacd; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv4; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv6; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.Subnet; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.Netmask; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.PrefixLength; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VxlanTunnel; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.Ethernet; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.L2; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.Routing; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.Vxlan; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.l2.Interconnection; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.l2.interconnection.BridgeBased; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.l2.interconnection.XconnectBased; -import org.opendaylight.yangtools.concepts.ListenerRegistration; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.openvpp.vppjapi.vppApi; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class VppIetfInterfaceListener implements DataTreeChangeListener<Interface>, AutoCloseable { - private static final Logger LOG = LoggerFactory.getLogger(VppIetfInterfaceListener.class); - private static final Splitter DOT_SPLITTER = Splitter.on('.'); - - private final ListenerRegistration<VppIetfInterfaceListener> registration; - private final DataBroker db; - private final vppApi api; - - private enum DataChangeType { - CREATE, UPDATE, DELETE - } - - /** - * TODO-ADD-JAVADOC. - */ - public VppIetfInterfaceListener(final DataBroker db, final vppApi api) { - this.db = db; - this.api = api; - InstanceIdentifier<Interface> iid = InstanceIdentifier - .create(Interfaces.class) - .child(Interface.class); - LOG.info("VPPCFG-INFO: Register listener for VPP Ietf Interface data changes"); - - DataTreeIdentifier<Interface> path = - new DataTreeIdentifier<Interface>(LogicalDatastoreType.CONFIGURATION, iid); - - registration = this.db.registerDataTreeChangeListener(path, this); - } - - @Override - public void onDataTreeChanged(final Collection<DataTreeModification<Interface>> changes) { - LOG.info("VPPCFG-INFO: swIf onDataTreeChanged()"); - for (DataTreeModification<Interface> change: changes) { - InstanceIdentifier<Interface> iid = change.getRootPath().getRootIdentifier(); - DataObjectModification<Interface> changeDiff = change.getRootNode(); - - switch (changeDiff.getModificationType()) { - case SUBTREE_MODIFIED: - case WRITE: - // create, modify or replace - createOrUpdateInterface(changeDiff); - break; - case DELETE: - deleteInterface(changeDiff); - break; - default: - LOG.info("Unsupported change type {} for {}", - changeDiff.getModificationType(), iid); - } - } - } - - private void vppSetVppInterfaceEthernetAndL2(final int swIfIndex, - final String swIfName, - final VppInterfaceAugmentation - vppInterface) { - int ctxId = 0; - int rv = -77; - int cnt = 0; - String apiName = ""; - - LOG.info("VPPCFG-INFO: <vppSetVppInterfaceEthernetAndL2>"); - LOG.info("VPPCFG-INFO: swIfIndex = {}", swIfIndex); - LOG.info("VPPCFG-INFO: swIfName = {}", swIfName); - LOG.info("VPPCFG-INFO: vppInterface = {}", vppInterface); - LOG.info("VPPCFG-INFO: </vppSetVppInterfaceEthernetAndL2>"); - if (vppInterface != null) { - Ethernet vppEth = vppInterface.getEthernet(); - if (vppEth != null) { - LOG.info("VPPCFG-INFO: {} Ethernet MTU = {}", - swIfName, vppEth.getMtu()); - /* DAW-FIXME: Need vpe-api msg to configure the Ethernet MTU */ - } - - L2 vppL2 = vppInterface.getL2(); - if (vppL2 != null) { - Interconnection ic = vppL2.getInterconnection(); - if (ic instanceof XconnectBased) { - XconnectBased xc = (XconnectBased) ic; - String outSwIfName = xc.getXconnectOutgoingInterface(); - LOG.info("VPPCFG-INFO: XconnectBased"); - LOG.info("VPPCFG-INFO: XconnectOutgoingInterface = {}", - outSwIfName); - - int outSwIfIndex = api.swIfIndexFromName(outSwIfName); - if (swIfIndex != -1) { - apiName = "api.swInterfaceSetL2Xconnect"; - ctxId = - api.swInterfaceSetL2Xconnect(swIfIndex, - outSwIfIndex, - (byte)1 /* enable */); - LOG.info("VPPCFG-INFO: {}() : outSwIfName = {}, " - + "outSwIfIndex = {}, ctxId = {}", apiName, - outSwIfName, outSwIfIndex, ctxId); - cnt = 0; - rv = -77; - while (rv == -77) { - rv = api.getRetval(ctxId, 1 /* release */); - cnt++; - } - if (rv < 0) { - LOG.warn("VPPCFG-WARNING: {}() ctxId = {} failed:" - + " retval = {}!", apiName, ctxId, rv); - /* DAW-FIXME: throw exception on failure? */ - } else { - LOG.info("VPPCFG-INFO: {}() ctxId = {} retval = {}" - + " after {} tries.", apiName, ctxId, - rv, cnt); - } - - } else { - LOG.warn("VPPCFG-WARNING: Unknown Outgoing Interface ({})" - + " specified", outSwIfName); - } - - } else if (ic instanceof BridgeBased) { - BridgeBased bb = (BridgeBased) ic; - String bdName = bb.getBridgeDomain(); - int bdId = api.bridgeDomainIdFromName(bdName); - if (bdId > 0) { - byte bvi = - bb.isBridgedVirtualInterface() ? (byte) 1 : (byte) 0; - byte shg = bb.getSplitHorizonGroup().byteValue(); - - LOG.info("VPPCFG-INFO: BridgeBased"); - LOG.info("VPPCFG-INFO: BridgeDomain = {}, bdId = {}", - bdName, bdId); - LOG.info("VPPCFG-INFO: SplitHorizonGroup = {}", - shg); - LOG.info("VPPCFG-INFO: isBridgedVirtualInterface = {}", - bvi); - - apiName = "api.swInterfaceSetL2Bridge"; - ctxId = - api.swInterfaceSetL2Bridge(swIfIndex, - bdId, shg, bvi, - (byte)1 /* enable */); - LOG.info("VPPCFG-INFO: {}() : bdId = {}, shg = {}, bvi = {}, ctxId = {}", apiName, bdId, - shg, bvi, ctxId); - cnt = 0; - rv = -77; - while (rv == -77) { - rv = api.getRetval(ctxId, 1 /* release */); - cnt++; - } - if (rv < 0) { - LOG.warn("VPPCFG-WARNING:{}() ctxId = {} failed: retval = {}!", apiName, ctxId, rv); - /* DAW-FIXME: throw exception on failure? */ - } else { - LOG.info("VPPCFG-INFO: {}() ctxId = {} retval = {} after {} tries.", apiName, ctxId, - rv, cnt); - } - - } else { - LOG.error("VPPCFG-ERROR: Bridge Domain {} does not exist!", bdName); - } - - } else { - LOG.error("VPPCFG-ERROR: unknonwn interconnection type!"); - } - } - } - } - - /** - * TODO-ADD-JAVADOC. - */ - public static int parseIp(final String address) { - int result = 0; - - // iterate over each octet - for (String part : DOT_SPLITTER.split(address)) { - // shift the previously parsed bits over by 1 byte - result = result << 8; - // set the low order bits to the current octet - result |= Integer.parseInt(part); - } - return result; - } - - private void createVxlanTunnel(final String swIfName, final Vxlan vxlan) { - Ipv4Address srcAddress = vxlan.getSrc(); - Ipv4Address dstAddress = vxlan.getDst(); - - int srcAddr = parseIp(srcAddress.getValue()); - int dstAddr = parseIp(dstAddress.getValue()); - int encapVrfId = vxlan.getEncapVrfId().intValue(); - int vni = vxlan.getVni().getValue().intValue(); - - int ctxId = api.vxlanAddDelTunnel((byte)1 /* is add */, srcAddr, dstAddr, encapVrfId, -1, vni); - String apiName = "api.vxlanAddDelTunnel"; - LOG.info("VPPCFG-INFO: {}({}, src: {}, dst: {} enabled ([]), ...) : ctxId = {}", - apiName, swIfName, srcAddress.getValue(), dstAddress.getValue(), ctxId); - - /* need to wait for creation of interface */ - int rv = -77; - int cnt = 0; - while (rv == -77) { - rv = api.getRetval(ctxId, 1 /* release */); - cnt++; - } - if (rv < 0) { - LOG.warn("VPPCFG-WARNING: {}() ctxId = {} failed: retval = {}!", apiName, ctxId, rv); - /* DAW-FIXME: throw exception on failure? */ - } else { - LOG.info("VPPCFG-INFO: {}() ctxId = {} retval = {} after {} tries.", apiName, ctxId, rv, cnt); - } - } - - private static byte [] ipv4AddressNoZoneToArray(final Ipv4AddressNoZone ipv4Addr) { - byte [] retval = new byte [4]; - String addr = ipv4Addr.getValue().toString(); - String [] dots = addr.split("\\."); - - for (int d = 3; d >= 0; d--) { - retval[d] = (byte)(Short.parseShort(dots[3 - d]) & 0xff); - } - return retval; - } - - private void vppSetInterface(final Interface swIf, final DataChangeType type, - final Interface originalIf) { - VppInterfaceAugmentation vppInterface = - swIf.getAugmentation(VppInterfaceAugmentation.class); // FIXME what if vppInterface is null? - int ctxId = 0; - int cnt = 0; - int rv = -77; - String apiName = ""; - - /* DAW-FIXME: If type == UPDATE, use originalDataObject to get - * state of api parameters which have not been changed. - * For now, all parameters must be set at the same time. - */ - LOG.info("VPPCFG-INFO: {} <swIf>", type); - LOG.info("VPPCFG-INFO: Name: {}", swIf.getName()); - LOG.info("VPPCFG-INFO: Desc: {}", swIf.getDescription()); - java.lang.Class<? extends - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfaceType> - ifType = swIf.getType(); - if (ifType != null) { - LOG.info("VPPCFG-INFO: Type: {}", swIf.getType().getSimpleName()); - } - LOG.info("VPPCFG-INFO: {} </swIf>", type); - - String swIfName = swIf.getName(); - int swIfIndex = api.swIfIndexFromName(swIfName); - - if ((ifType != null) && ifType.isAssignableFrom(EthernetCsmacd.class)) { - if (swIfIndex != -1) { - LOG.info("VPPCFG-INFO: {} : swIfIndex = {}", swIfName, swIfIndex); - - /* set vpp ethernet and l2 containers */ - vppSetVppInterfaceEthernetAndL2(swIfIndex, swIfName, - vppInterface); - - byte enabled = swIf.isEnabled() ? (byte) 1 : (byte) 0; - apiName = "api.swInterfaceSetFlags"; - ctxId = api.swInterfaceSetFlags(swIfIndex, - enabled, - enabled, - (byte)0 /* deleted */); - LOG.info("VPPCFG-INFO: {}({} ([]), enabled ([]), ...) : ctxId = {}", apiName, swIfName, swIfIndex, - enabled, ctxId); - cnt = 0; - rv = -77; - while (rv == -77) { - rv = api.getRetval(ctxId, 1 /* release */); - cnt++; - } - if (rv < 0) { - LOG.warn("VPPCFG-WARNING: api.swInterfaceSetFlags() ctxId = {} failed: retval = {}!", ctxId, rv); - /* DAW-FIXME: throw exception on failure? */ - } else { - LOG.info("VPPCFG-INFO: {}() ctxId = {} retval = {} after {} tries.", apiName, ctxId, rv, cnt); - } - } else { - LOG.error("VPPCFG-ERROR: {} not found!", swIf.getType().getSimpleName()); - LOG.error("VPPCFG-ERROR: cannot create {} type interfaces : ignoring create request for {} !", - swIf.getType().getSimpleName(), swIf.getName()); - } - - } else if ((ifType != null) && ifType.isAssignableFrom(VxlanTunnel.class) - && vppInterface != null) { // FIXME handle vppInterface==null case in consistent manner - LOG.info("VPPCFG-INFO: VxLAN tunnel configuration"); - - // TODO: check name of interface, make use of renumber to change vpp - // interface name to desired one - - if (swIfIndex != -1) { - // interface exists in vpp - if (type == DataChangeType.DELETE) { - // TODO - } else { - // TODO - Vxlan vxlan = vppInterface.getVxlan(); - - LOG.info("Vxlan update: {}", vxlan); - } - } else { - // interface does not exist in vpp - if (type == DataChangeType.DELETE) { - // cannot delete non existent interface - LOG.error("VPPCFG-ERROR: Cannot delete non existing interface ({})", swIf.getName()); - } else { - Vxlan vxlan = vppInterface.getVxlan(); - - createVxlanTunnel(swIfName, vxlan); - - // refresh interfaces to be able to get ifIndex - api.swInterfaceDump((byte)1, "vxlan".getBytes()); - - int newSwIfIndex = api.swIfIndexFromName(swIfName); - - /* set vpp ethernet and l2 containers */ - vppSetVppInterfaceEthernetAndL2(newSwIfIndex, - swIfName, - vppInterface); - - byte enabled = swIf.isEnabled() ? (byte) 1 : (byte) 0; - ctxId = api.swInterfaceSetFlags(newSwIfIndex, - enabled, - enabled, - (byte)0 /* deleted */); - - swIfIndex = newSwIfIndex; - - apiName = "api.swInterfaceSetFlags"; - LOG.info("VPPCFG-INFO: {}({} ({}), enabled ({}), ...) : ctxId = {}", apiName, swIfName, - newSwIfIndex, enabled, ctxId); - cnt = 0; - rv = -77; - while (rv == -77) { - rv = api.getRetval(ctxId, 1 /* release */); - cnt++; - } - if (rv < 0) { - LOG.warn("VPPCFG-WARNING: {}() ctxId = {} failed: retval = {}!", apiName, ctxId, rv); - /* DAW-FIXME: throw exception on failure? */ - } else { - LOG.info("VPPCFG-INFO: {}() ctxId = {} retval = {} after {} tries.", apiName, ctxId, rv, cnt); - } - } - } - - /* DAW-FIXME: Add additional interface types here. - * - * } else if ((ifType != null) && ifType.isAssignableFrom(*.class)) { - */ - } else if (ifType != null) { - LOG.error("VPPCFG-ERROR: Unsupported interface type ({}) : {} cannot be created!", ifType.getSimpleName(), - swIf.getName()); - } - - if (swIfIndex == -1) { - LOG.warn("VPPCFG-INFO: Unknown Interface {}", swIfName); - return; - } - - if (swIf.getDescription() != null) { - api.setInterfaceDescription(swIfName, swIf.getDescription()); - } else { - api.setInterfaceDescription(swIfName, ""); - } - - if (vppInterface != null) { // FIXME handle vppInterface==null case in consistent manner - Routing rt = vppInterface.getRouting(); - int vrfId = (rt != null) - ? rt.getVrfId().intValue() - : 0; - LOG.info("VPPCFG-INFO: vrfId = {}", vrfId); - if (vrfId > 0) { - apiName = "api.swInterfaceSetTable"; - ctxId = api.swInterfaceSetTable(swIfIndex, - (byte) 0, /* isIpv6 */ - vrfId); - LOG.info("VPPCFG-INFO: {}({} ([]), 0 /* isIpv6 */, {} /* vrfId */)" - + " : ctxId = {}", apiName, swIfName, swIfIndex, - vrfId, ctxId); - cnt = 0; - rv = -77; - while (rv == -77) { - rv = api.getRetval(ctxId, 1 /* release */); - cnt++; - } - if (rv < 0) { - LOG.warn("VPPCFG-WARNING: api.swInterfaceSetTable() ctxId = {} failed: retval = {}!", ctxId, rv); - /* DAW-FIXME: throw exception on failure? */ - } else { - LOG.info("VPPCFG-INFO: {}() ctxId = {} retval = {} after {} tries.", apiName, ctxId, rv, cnt); - } - } - } - - Interface1 ipIf = swIf.getAugmentation(Interface1.class); - LOG.info("VPPCFG-INFO: ipIf = {}", ipIf); - if (ipIf != null) { - Ipv4 v4 = ipIf.getIpv4(); - if (v4 != null) { - LOG.info("VPPCFG-INFO: v4 = {}", v4); - - for (Address v4Addr : v4.getAddress()) { - Subnet subnet = v4Addr.getSubnet(); - - if (subnet instanceof PrefixLength) { - Short plen = ((PrefixLength)subnet).getPrefixLength(); - byte [] addr = ipv4AddressNoZoneToArray(v4Addr.getIp()); - - if ((plen > 0) && (addr != null)) { - apiName = "api.swInterfaceAddDelAddress"; - ctxId = - api.swInterfaceAddDelAddress(swIfIndex, - (byte)1 /* isAdd */, - (byte)0 /* isIpv6 */, - (byte)0 /* delAll */, - plen.byteValue(), addr); - LOG.info("VPPCFG-INFO: {}({}/{}) to {} ({}): {}() returned ctxId = {}", apiName, addr, - plen, swIfName, swIfIndex, ctxId); - cnt = 0; - rv = -77; - while (rv == -77) { - rv = api.getRetval(ctxId, 1 /* release */); - cnt++; - } - if (rv < 0) { - LOG.warn("VPPCFG-WARNING: {}() ctxId = {} failed: retval = {}!", apiName, - ctxId, rv); - /* DAW-FIXME: throw exception on failure? */ - } else { - LOG.info("VPPCFG-INFO: {}() ctxId = {} retval = {} after {} tries.", apiName, - ctxId, rv, cnt); - } - } else { - LOG.warn("VPPCFG-WARNING: Malformed ipv4 address ({}/{}) " - + "specified for {} ({}): ignoring config!", - addr, plen, swIfName, swIfIndex); - } - } else if (subnet instanceof Netmask) { - LOG.warn("VPPCFG-WARNING: Unsupported ipv4 address subnet type 'Netmask' " - + "specified for {} ({}): ignoring config!", - swIfName, swIfIndex); - } else { - LOG.error("VPPCFG-ERROR: Unknown ipv4 address subnet type " - + "specified for {} ({}): ignoring config!", - swIfName, swIfIndex); - } - } - } - - Ipv6 v6 = ipIf.getIpv6(); - if (v6 != null) { - LOG.info("VPPCFG-INFO: v6 = {}", v6); - - // DAW-FIXME: Add Ipv6 address support. - LOG.warn("VPPCFG-WARNING: Ipv6 address support TBD: ignoring config!"); - } - } - } - - private void createOrUpdateInterface(final DataObjectModification<Interface> changeDiff) { - if (changeDiff.getDataBefore() == null) { - // create - vppSetInterface(changeDiff.getDataAfter(), - DataChangeType.CREATE, null); - } else { - // update - vppSetInterface(changeDiff.getDataAfter(), - DataChangeType.UPDATE, - changeDiff.getDataBefore()); - } - } - - private static void deleteInterface(final DataObjectModification<Interface> changeDiff) { - Interface swIf = changeDiff.getDataBefore(); - LOG.info("VPPCFG-INFO: <swIf>"); - LOG.info("VPPCFG-INFO: Name: {},", swIf.getName()); - LOG.info("VPPCFG-INFO: Desc: {}", swIf.getDescription()); - LOG.info("VPPCFG-INFO: Type: {}", swIf.getType().getSimpleName()); - LOG.info("VPPCFG-INFO: </swIf>"); - - if (swIf.getType().isAssignableFrom(EthernetCsmacd.class)) { - LOG.error("VPPCFG-ERROR: {} Interface {} cannot be deleted!", - swIf.getType().getSimpleName(), - swIf.getName()); - - /* DAW-FIXME: Add additional interface types here. - * - * } else if (swIf.getType().isAssignableFrom(*.class)) { - */ - - } else { - LOG.error("VPPCFG-ERROR: Unsupported interface type ({}) : {} cannot be deleted!", - swIf.getType().getSimpleName(), - swIf.getName()); - } - } - - @Override - public void close() throws Exception { - registration.close(); - } -} diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/VppPollOperDataImpl.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/VppPollOperDataImpl.java deleted file mode 100644 index aa607c771..000000000 --- a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/VppPollOperDataImpl.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * 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. - */ - -package io.fd.honeycomb.v3po.impl; - -import com.google.common.util.concurrent.CheckedFuture; -import com.google.common.util.concurrent.Futures; -import java.util.HashMap; -import java.util.concurrent.Future; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.V3poService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppPollOperDataOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppPollOperDataOutputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppState; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.opendaylight.yangtools.yang.common.RpcResultBuilder; -import org.openvpp.vppjapi.vppApi; -import org.openvpp.vppjapi.vppBridgeDomainDetails; -import org.openvpp.vppjapi.vppBridgeDomainInterfaceDetails; -import org.openvpp.vppjapi.vppL2Fib; -import org.openvpp.vppjapi.vppVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class VppPollOperDataImpl implements V3poService { - private static final Logger LOG = LoggerFactory.getLogger(VppPollOperDataImpl.class); - private static final InstanceIdentifier<VppState> VPP_STATE = InstanceIdentifier.create(VppState.class); - private vppVersion version; - private final DataBroker db; - private int[] bdIds; - private final HashMap<Integer, vppL2Fib[]> l2fibByBdId = new HashMap<Integer, vppL2Fib[]>(); - private final vppApi api; - - /** - * TODO-ADD-JAVADOC. - * @param api - */ - public VppPollOperDataImpl(final vppApi api, final DataBroker dataBroker) { - this.api = api; - db = dataBroker; - } - - /** - * TODO-ADD-JAVADOC. - */ - public DataBroker getDataBroker() { - return db; - } - - /** - * TODO-ADD-JAVADOC. - * Updates operational data - */ - public void updateOperational() { - V3poApiRequest req = new V3poApiRequest(api, this); - version = api.getVppVersion(); - - bdIds = api.bridgeDomainDump(-1); - - // TODO: we don't need to cache BDs now that we got rid of callbacks - l2fibByBdId.clear(); - if (bdIds != null) { - for (int bdId : bdIds) { - l2fibByBdId.put(bdId, api.l2FibTableDump(bdId)); - } - } - req.swInterfaceDumpAll(); - - // build vpp-state - VppStateCustomBuilder stateBuilder = new VppStateCustomBuilder(); - - // bridge domains - for (int bdId : bdIds) { - vppBridgeDomainDetails bd = api.getBridgeDomainDetails(bdId); - VppStateBridgeDomainBuilder bdBuilder = - new VppStateBridgeDomainBuilder( - bd.name, bd.flood, bd.uuFlood, - bd.arpTerm, bd.forward, bd.learn); - - for (vppBridgeDomainInterfaceDetails bdIf : bd.interfaces) { - if (bdIf.interfaceName != null) { - bdBuilder.addInterface(bdIf.interfaceName, - bdIf.interfaceName.equals(bd.bviInterfaceName), - bdIf.splitHorizonGroup); - } - } - - vppL2Fib[] bdFibs = l2fibByBdId.get(bdId); - - for (vppL2Fib fib : bdFibs) { - bdBuilder.addL2Fib(fib.filter, fib.bridgedVirtualInterface, - fib.outgoingInterface, fib.physAddress, - fib.staticConfig); - } - - stateBuilder.addBridgeDomain(bdBuilder.build()); - } - - stateBuilder.setVersion(version); - - // write to oper - writeVppState(VPP_STATE, stateBuilder.build()); - } - - @Override - public Future<RpcResult<VppPollOperDataOutput>> vppPollOperData() { - updateOperational(); - - VppPollOperDataOutput output = new VppPollOperDataOutputBuilder() - .setStatus(Long.valueOf(1)).build(); - - return RpcResultBuilder.success(output).buildFuture(); - } - - private void writeVppState(final InstanceIdentifier<VppState> iid, final VppState vppState) { - WriteTransaction transaction = db.newWriteOnlyTransaction(); - - //LOG.info("VPPOPER-INFO: Writing vpp-state to oper DataStore."); - transaction.put(LogicalDatastoreType.OPERATIONAL, iid, vppState); - - CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit(); - Futures.addCallback(future, new LoggingFuturesCallBack<Void>( - "VPPOPER-WARNING: Failed to write vpp-state to oper datastore", LOG)); - } -} - diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/VppStateBridgeDomainBuilder.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/VppStateBridgeDomainBuilder.java deleted file mode 100644 index d547342bd..000000000 --- a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/VppStateBridgeDomainBuilder.java +++ /dev/null @@ -1,102 +0,0 @@ -/*
- * 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.
- */
-
-package io.fd.honeycomb.v3po.impl;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomain;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomainBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.bridge.domain.Interface;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.bridge.domain.InterfaceBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.bridge.domain.L2Fib;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.bridge.domain.L2Fib.Action;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.bridge.domain.L2FibBuilder;
-
-public class VppStateBridgeDomainBuilder {
- private BridgeDomainBuilder bdStateBuilder = new BridgeDomainBuilder();
- private List<Interface> bdIfaces = new ArrayList<Interface>();
- private List<L2Fib> bdL2Fibs = new ArrayList<L2Fib>();
-
- /**
- * TODO-ADD-JAVADOC.
- */
- public VppStateBridgeDomainBuilder(String bdName, boolean flood,
- boolean unknownUnicastFlood,
- boolean arpTermination,
- boolean forward, boolean learn) {
- bdStateBuilder
- .setName(bdName)
- .setFlood(flood)
- .setUnknownUnicastFlood(unknownUnicastFlood)
- .setArpTermination(arpTermination)
- .setForward(forward)
- .setLearn(learn);
- }
-
- /**
- * TODO-ADD-JAVADOC.
- */
- public void addInterface(String interfaceName, boolean bvi,
- short splitHorizonGroup) {
- InterfaceBuilder ifBuilder = new InterfaceBuilder();
- ifBuilder
- .setName(interfaceName)
- .setBridgedVirtualInterface(bvi)
- .setSplitHorizonGroup(splitHorizonGroup);
-
- bdIfaces.add(ifBuilder.build());
- }
-
- private static String getMacAddress(byte[] mac) {
- StringBuilder sb = new StringBuilder(18);
- for (byte b : mac) {
- if (sb.length() > 0) {
- sb.append(':');
- }
- sb.append(String.format("%02x", b));
- }
- return sb.toString();
- }
-
- /**
- * TODO-ADD-JAVADOC.
- */
- public void addL2Fib(boolean filter, boolean bvi,
- String outgoingIfaceName, byte[] physAddress,
- boolean isStatic) {
- L2FibBuilder l2fibBuilder = new L2FibBuilder();
- l2fibBuilder
- .setAction((filter ? Action.Filter : Action.Forward))
- .setBridgedVirtualInterface(bvi)
- .setOutgoingInterface(outgoingIfaceName)
- .setPhysAddress(new PhysAddress(getMacAddress(physAddress)))
- .setStaticConfig(isStatic);
-
- bdL2Fibs.add(l2fibBuilder.build());
- }
-
- /**
- * TODO-ADD-JAVADOC.
- */
- public BridgeDomain build() {
- bdStateBuilder.setInterface(bdIfaces);
- bdStateBuilder.setL2Fib(bdL2Fibs);
- return bdStateBuilder.build();
- }
-}
diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/VppStateCustomBuilder.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/VppStateCustomBuilder.java deleted file mode 100644 index 86e44ec0b..000000000 --- a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/VppStateCustomBuilder.java +++ /dev/null @@ -1,73 +0,0 @@ -/*
- * 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.
- */
-
-package io.fd.honeycomb.v3po.impl;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppState;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppStateBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.BridgeDomainsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.VersionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomain;
-import org.openvpp.vppjapi.vppVersion;
-
-public class VppStateCustomBuilder {
- VppStateBuilder stateBuilder = new VppStateBuilder();
-
- List<BridgeDomain> bridgeDomains = new ArrayList<BridgeDomain>();
-
- /**
- * TODO-ADD-JAVADOC.
- */
- public void setVersion(String name, String branch, String buildDate,
- String buildDir) {
- stateBuilder.setVersion(
- new VersionBuilder()
- .setBranch(branch)
- .setBuildDate(buildDate)
- .setBuildDirectory(buildDir)
- .setName(name)
- .build());
- }
-
- /**
- * TODO-ADD-JAVADOC.
- */
- public void setVersion(vppVersion vppVer) {
- setVersion(vppVer.programName, vppVer.gitBranch,
- vppVer.buildDate, vppVer.buildDirectory);
- }
-
- /**
- * TODO-ADD-JAVADOC.
- */
- public void addBridgeDomain(BridgeDomain bd) {
- bridgeDomains.add(bd);
- }
-
- /**
- * TODO-ADD-JAVADOC.
- */
- public VppState build() {
- stateBuilder.setBridgeDomains(
- new BridgeDomainsBuilder()
- .setBridgeDomain(bridgeDomains)
- .build());
- return stateBuilder.build();
- }
-}
diff --git a/v3po/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/v3po/impl/rev141210/V3poModule.java b/v3po/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/v3po/impl/rev141210/V3poModule.java index 697213b3c..b22ece04f 100644 --- a/v3po/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/v3po/impl/rev141210/V3poModule.java +++ b/v3po/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/v3po/impl/rev141210/V3poModule.java @@ -16,21 +16,10 @@ package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.impl.rev141210; -import io.fd.honeycomb.v3po.impl.V3poProvider; -import java.util.Collection; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; -import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; -import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; +import io.fd.honeycomb.v3po.impl.NetconfFacadeHoneycombBindingBroker; +import org.opendaylight.controller.sal.core.api.AbstractProvider; import org.opendaylight.controller.sal.core.api.Broker; -import org.opendaylight.controller.sal.core.api.Provider; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.BridgeDomains; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomain; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.impl.schema.Builders; +import org.opendaylight.controller.sal.core.api.model.SchemaService; public class V3poModule extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.impl.rev141210.AbstractV3poModule { @@ -54,58 +43,17 @@ public class V3poModule extends @Override public java.lang.AutoCloseable createInstance() { - final Broker domBroker = getDomBrokerDependency(); - domBroker.registerProvider(new InitializationProvider()); - final V3poProvider provider = new V3poProvider(domBroker, getVppJapiDependency(), getSerializerDependency(), - getDomDataBrokerDependency()); - getBrokerDependency().registerProvider(provider); - return provider; - } - - /** - * Writes list parents as a workaround for ODL issue TODO remove (also remove from yang model and cfg) and fix ODL - * bug-5382 - */ - private class InitializationProvider implements Provider { - @Override - public void onSessionInitiated(final Broker.ProviderSession providerSession) { - final DOMDataBroker service = providerSession.getService(DOMDataBroker.class); - final DOMDataWriteTransaction domDataWriteTransaction = service.newWriteOnlyTransaction(); - - // Initialize interfaces list - YangInstanceIdentifier.NodeIdentifier nodeId = getNodeId(Interfaces.QNAME); - YangInstanceIdentifier interfacesYid = YangInstanceIdentifier.create(nodeId); - domDataWriteTransaction.merge(LogicalDatastoreType.CONFIGURATION, - interfacesYid, Builders.containerBuilder().withNodeIdentifier(nodeId) - .withChild(Builders.mapBuilder().withNodeIdentifier(getNodeId(Interface.QNAME)).build()) - .build()); - - // Initialize bridge domains list - nodeId = getNodeId(BridgeDomains.QNAME); - interfacesYid = YangInstanceIdentifier.create(getNodeId( - org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.Vpp.QNAME), nodeId); - domDataWriteTransaction.merge(LogicalDatastoreType.CONFIGURATION, - interfacesYid, Builders.containerBuilder().withNodeIdentifier(nodeId) - .withChild(Builders.mapBuilder().withNodeIdentifier(getNodeId(BridgeDomain.QNAME)).build()) - .build()); + final Broker.ProviderSession providerSession = + getDomBrokerDependency().registerProvider(new AbstractProvider() { + @Override + public void onSessionInitiated(final Broker.ProviderSession providerSession) { + // NOOP + } + }); + final SchemaService schemaBiService = providerSession.getService(SchemaService.class); - try { - domDataWriteTransaction.submit().checkedGet(); - } catch (TransactionCommitFailedException e) { - throw new IllegalStateException("Unable to initialize parent data structures", e); - } - } - - private YangInstanceIdentifier.NodeIdentifier getNodeId(final QName qname) { - return new YangInstanceIdentifier.NodeIdentifier(qname); - } - - @Override - public Collection<ProviderFunctionality> getProviderFunctionality() { - return null; - } + return new NetconfFacadeHoneycombBindingBroker(getHoneycombDomDataBrokerDependency(), schemaBiService); } - } diff --git a/v3po/impl/src/main/yang/v3po-impl.yang b/v3po/impl/src/main/yang/v3po-impl.yang index 9509b02ec..b4968576f 100644 --- a/v3po/impl/src/main/yang/v3po-impl.yang +++ b/v3po/impl/src/main/yang/v3po-impl.yang @@ -27,15 +27,6 @@ module v3po-impl { augment "/config:modules/config:module/config:configuration" { case v3po { when "/config:modules/config:module/config:type = 'v3po'"; - container broker { - uses config:service-ref { - refine type { - mandatory true; - config:required-identity md-sal-binding:binding-broker-osgi-registry; - } - } - } - container dom-broker { uses config:service-ref { refine type { @@ -45,25 +36,7 @@ module v3po-impl { } } - container vpp-japi { - uses config:service-ref { - refine type { - mandatory true; - config:required-identity vjc:vpp-japi; - } - } - } - - container serializer { - uses config:service-ref { - refine type { - mandatory true; - config:required-identity md-sal-binding:binding-normalized-node-serializer; - } - } - } - - container dom-data-broker { + container honeycomb-dom-data-broker { uses config:service-ref { refine type { mandatory true; diff --git a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VppDataBrokerInitializationProviderTest.java b/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VppDataBrokerInitializationProviderTest.java deleted file mode 100644 index ee7619cee..000000000 --- a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VppDataBrokerInitializationProviderTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2016 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. - */ - -package io.fd.honeycomb.v3po.impl.data; - -import static org.junit.Assert.assertNotNull; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.MockitoAnnotations.initMocks; - -import com.google.common.util.concurrent.CheckedFuture; -import io.fd.honeycomb.v3po.impl.VppDataBrokerInitializationProvider; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; -import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; -import org.opendaylight.yangtools.binding.data.codec.api.BindingNormalizedNodeSerializer; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class VppDataBrokerInitializationProviderTest { - - @Mock - private DataBroker bindingBroker; - @Mock - private WriteTransaction writeTx; - @Mock - private BindingNormalizedNodeSerializer serializer; - @Mock - private DOMDataBroker domDataBroker; - - private VppDataBrokerInitializationProvider provider; - - @Before - public void setUp() throws Exception { - initMocks(this); - doReturn(writeTx).when(bindingBroker).newWriteOnlyTransaction(); - provider = new VppDataBrokerInitializationProvider(bindingBroker, serializer, domDataBroker); - } - - @Test - public void testGetProviderFunctionality() { - assertNotNull(provider.getProviderFunctionality()); - } - - @Test - public void testClose() throws Exception { - doReturn(mock(CheckedFuture.class)).when(writeTx).submit(); - provider.close(); - verify(writeTx).delete(eq(LogicalDatastoreType.CONFIGURATION), any(InstanceIdentifier.class)); - verify(writeTx).submit(); - } - - @Test(expected = IllegalStateException.class) - public void testCloseFailed() throws Exception { - doReturn(writeTx).when(bindingBroker).newWriteOnlyTransaction(); - doThrow(TransactionCommitFailedException.class).when(writeTx).submit(); - provider.close(); - verify(writeTx).delete(eq(LogicalDatastoreType.CONFIGURATION), any(InstanceIdentifier.class)); - } -}
\ No newline at end of file diff --git a/v3po/impl/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/v3po/impl/rev141210/V3poModuleTest.java b/v3po/impl/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/v3po/impl/rev141210/V3poModuleTest.java index 845e679d6..3d8e79641 100644 --- a/v3po/impl/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/v3po/impl/rev141210/V3poModuleTest.java +++ b/v3po/impl/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/v3po/impl/rev141210/V3poModuleTest.java @@ -17,11 +17,10 @@ package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.im import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import io.fd.honeycomb.v3po.impl.V3poProvider; import javax.management.ObjectName; import org.junit.Test; import org.opendaylight.controller.config.api.DependencyResolver; @@ -29,6 +28,8 @@ import org.opendaylight.controller.config.api.JmxAttribute; import org.opendaylight.controller.config.api.ModuleIdentifier; import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; +import org.opendaylight.controller.sal.core.api.Broker; +import org.opendaylight.controller.sal.core.api.Provider; import org.opendaylight.yangtools.binding.data.codec.api.BindingNormalizedNodeSerializer; public class V3poModuleTest { @@ -41,7 +42,6 @@ public class V3poModuleTest { module.customValidation(); } - @Test public void testCreateInstance() throws Exception { // configure mocks @@ -52,6 +52,7 @@ public class V3poModuleTest { final org.opendaylight.controller.sal.core.api.Broker domBroker = mock(org.opendaylight.controller.sal.core.api.Broker.class); when(dependencyResolver.resolveInstance(eq(org.opendaylight.controller.sal.core.api.Broker.class), any(ObjectName.class), any(JmxAttribute.class))) .thenReturn(domBroker); + doReturn(mock(Broker.ProviderSession.class)).when(domBroker).registerProvider(any(Provider.class)); when(dependencyResolver.resolveInstance(eq(BindingNormalizedNodeSerializer.class), any(ObjectName.class), any(JmxAttribute.class))) .thenReturn(mock(BindingNormalizedNodeSerializer.class)); when(dependencyResolver.resolveInstance(eq(DOMDataBroker.class), any(ObjectName.class), any(JmxAttribute.class))) @@ -63,9 +64,6 @@ public class V3poModuleTest { // getInstance calls resolveInstance to get the broker dependency and then calls createInstance AutoCloseable closeable = module.getInstance(); - // verify that the module registered the returned provider with the broker - verify(broker).registerProvider((V3poProvider)closeable); - // ensure no exceptions on close closeable.close(); } |