diff options
author | 2016-04-14 15:22:06 +0200 | |
---|---|---|
committer | 2016-04-15 10:56:42 +0200 | |
commit | 1e37dbc5e73141fb6927ab68304f4ef4671243c7 (patch) | |
tree | 129c15d0236563e6c8cc5bd20b3b314f0397a8a9 /v3po/v3po2vpp/src/main/java/io | |
parent | 83a373b7cb6274e84281519d32417d6eda2a5145 (diff) |
HONEYCOMB-38: Fix vpp interface customizers
The order of execution was not correct
+ CompositeWriter ignored some changes
Change-Id: I53fd9fda4b7a0379e0fa8451fa894865f67ebace
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'v3po/v3po2vpp/src/main/java/io')
7 files changed, 124 insertions, 267 deletions
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/InterfaceCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/InterfaceCustomizer.java index 6b91e2e0a..30600d81e 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/InterfaceCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/InterfaceCustomizer.java @@ -19,6 +19,9 @@ package io.fd.honeycomb.v3po.translate.v3po.interfaces; import io.fd.honeycomb.v3po.translate.Context; import io.fd.honeycomb.v3po.translate.spi.write.ListWriterCustomizer; import io.fd.honeycomb.v3po.translate.v3po.util.VppApiCustomizer; +import io.fd.honeycomb.v3po.translate.v3po.util.VppApiInvocationException; +import io.fd.honeycomb.v3po.translate.v3po.utils.V3poUtils; +import io.fd.honeycomb.v3po.translate.write.WriteFailedException; import java.util.List; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; @@ -27,14 +30,15 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces. import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.openvpp.vppjapi.vppApi; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Ietf interface write customizer that only caches interface objects for child writers */ public class InterfaceCustomizer extends VppApiCustomizer implements ListWriterCustomizer<Interface, InterfaceKey> { - public static final String IFC_AFTER_CTX = InterfaceCustomizer.class.toString() + "ifcAfter"; - public static final String IFC_BEFORE_CTX = InterfaceCustomizer.class.toString() + "ifcBefore"; + private static final Logger LOG = LoggerFactory.getLogger(InterfaceCustomizer.class); public InterfaceCustomizer(final vppApi vppApi) { super(vppApi); @@ -43,24 +47,38 @@ public class InterfaceCustomizer extends VppApiCustomizer implements ListWriterC @Override public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Interface> id, @Nonnull final Interface dataAfter, - @Nonnull final Context writeContext) { - writeContext.put(IFC_AFTER_CTX, dataAfter); + @Nonnull final Context writeContext) + throws WriteFailedException { + + try { + setInterface(id, dataAfter); + } catch (VppApiInvocationException e) { + LOG.warn("Update of VppInterfaceAugment failed", e); + throw new WriteFailedException.CreateFailedException(id, dataAfter, e); + } } @Override public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<Interface> id, @Nonnull final Interface dataBefore, @Nonnull final Interface dataAfter, - @Nonnull final Context writeContext) { - writeContext.put(IFC_BEFORE_CTX, dataBefore); - writeContext.put(IFC_AFTER_CTX, dataAfter); + @Nonnull final Context writeContext) + throws WriteFailedException.UpdateFailedException { + + try { + updateInterface(id, dataBefore, dataAfter); + } catch (VppApiInvocationException e) { + LOG.warn("Update of VppInterfaceAugment failed", e); + throw new WriteFailedException.UpdateFailedException(id, dataBefore, dataAfter, e); + } } @Override public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Interface> id, @Nonnull final Interface dataBefore, @Nonnull final Context writeContext) { - writeContext.put(IFC_BEFORE_CTX, dataBefore); + + // TODO Handle deletes } @Nonnull @@ -69,4 +87,64 @@ public class InterfaceCustomizer extends VppApiCustomizer implements ListWriterC @Nonnull final DataObject parentData) { return ((Interfaces) parentData).getInterface(); } + + + private void setInterface(final InstanceIdentifier<Interface> id, final Interface swIf) + throws VppApiInvocationException, WriteFailedException { + LOG.info("Setting interface {}, type: {}", swIf.getName(), swIf.getType().getSimpleName()); + LOG.debug("Setting interface {}", swIf); + + String swIfName = swIf.getName(); + int swIfIndex = getVppApi().swIfIndexFromName(swIfName); + + setInterfaceAttributes(swIf, swIfName); + } + + private void setInterfaceAttributes(final Interface swIf, final String swIfName) + throws VppApiInvocationException { + LOG.debug("Creating {} interface {}", swIf.getType().getSimpleName(), swIf.getName()); + + setInterfaceFlags(swIfName, getVppApi().swIfIndexFromName(swIfName), + swIf.isEnabled() ? (byte) 1 : (byte) 0); + + setDescription(swIf); + } + + private void updateInterface(final InstanceIdentifier<Interface> id, + final Interface dataBefore, + final Interface dataAfter) throws VppApiInvocationException { + LOG.info("Updating interface {}, type: {}", dataAfter.getName(), dataAfter.getType().getSimpleName()); + LOG.debug("Updating interface {}", dataAfter); + + String swIfName = dataAfter.getName(); + int swIfIndex = getVppApi().swIfIndexFromName(swIfName); + + setInterfaceAttributes(dataAfter, swIfName); + } + + private void setInterfaceFlags(final String swIfName, final int swIfIndex, final byte enabled) + throws VppApiInvocationException { + int ctxId = getVppApi().swInterfaceSetFlags(swIfIndex, enabled, enabled, (byte) 0 /* deleted */); + + LOG.debug("Updating interface flags for: {}, index: {}, enabled: {}, ctxId: {}", swIfName, swIfIndex, + enabled, ctxId); + + final int rv = V3poUtils.waitForResponse(ctxId, getVppApi()); + if (rv < 0) { + LOG.warn("Failed to update interface flags for: {}, index: {}, enabled: {}, ctxId: {}", swIfName, swIfIndex, + enabled, ctxId); + throw new VppApiInvocationException("swInterfaceSetFlags", ctxId, rv); + } else { + LOG.debug("Interface flags updated successfully for: {}, index: {}, enabled: {}, ctxId: {}", + swIfName, swIfIndex, enabled, ctxId); + } + } + + private void setDescription(final Interface swIf) { + if (swIf.getDescription() != null) { + getVppApi().setInterfaceDescription(swIf.getName(), swIf.getDescription()); + } else { + getVppApi().setInterfaceDescription(swIf.getName(), ""); + } + } } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/L2Customizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/L2Customizer.java index e596f8fbf..b9296b481 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/L2Customizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/L2Customizer.java @@ -55,11 +55,11 @@ public class L2Customizer extends VppApiCustomizer implements ChildWriterCustomi public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<L2> id, @Nonnull final L2 dataAfter, @Nonnull final Context writeContext) throws WriteFailedException { - final Interface ifc = (Interface) writeContext.get(InterfaceCustomizer.IFC_AFTER_CTX); - final int swIfc = getSwIfc(ifc); + final String ifcName = id.firstKeyOf(Interface.class).getName(); + final int swIfc = getSwIfc(ifcName); try { - setL2(id, swIfc, ifc, dataAfter); + setL2(id, swIfc, ifcName, dataAfter); } catch (VppApiInvocationException e) { LOG.warn("Write of L2 failed", e); throw new WriteFailedException.CreateFailedException(id, dataAfter, e); @@ -70,49 +70,45 @@ public class L2Customizer extends VppApiCustomizer implements ChildWriterCustomi public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<L2> id, @Nonnull final L2 dataBefore, @Nonnull final L2 dataAfter, @Nonnull final Context writeContext) throws WriteFailedException { - final Interface ifcBefore = (Interface) writeContext.get(InterfaceCustomizer.IFC_BEFORE_CTX); - final Interface ifcAfter = (Interface) writeContext.get(InterfaceCustomizer.IFC_BEFORE_CTX); - final int swIfc = getSwIfc(ifcBefore); + final String ifcName = id.firstKeyOf(Interface.class).getName(); + final int swIfc = getSwIfc(ifcName); // TODO handle update properly (if possible) try { - setL2(id, swIfc, ifcAfter, dataAfter); + setL2(id, swIfc, ifcName, dataAfter); } catch (VppApiInvocationException e) { LOG.warn("Update of L2 failed", e); throw new WriteFailedException.UpdateFailedException(id, dataBefore, dataAfter, e); } } - private int getSwIfc(final Interface ifcBefore) { - int swIfcIndex = getVppApi().swIfIndexFromName(ifcBefore.getName()); - checkArgument(swIfcIndex != -1, "Interface %s does not exist", ifcBefore.getName()); + private int getSwIfc(final String ifcName) { + int swIfcIndex = getVppApi().swIfIndexFromName(ifcName); + checkArgument(swIfcIndex != -1, "Interface %s does not exist", ifcName); return swIfcIndex; } @Override public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<L2> id, @Nonnull final L2 dataBefore, @Nonnull final Context writeContext) { - final Interface ifcBefore = (Interface) writeContext.get(InterfaceCustomizer.IFC_BEFORE_CTX); - - final int swIfc = getSwIfc(ifcBefore); // TODO implement delete (if possible) } - private void setL2(final InstanceIdentifier<L2> id, final int swIfIndex, final Interface ifc, final L2 vppL2) + private void setL2(final InstanceIdentifier<L2> id, final int swIfIndex, final String ifcName, final L2 vppL2) throws VppApiInvocationException, WriteFailedException { - LOG.debug("Setting L2 for interface: %s", ifc.getName()); + LOG.debug("Setting L2 for interface: %s", ifcName); // Nothing besides interconnection here - setInterconnection(id, swIfIndex, ifc, vppL2); + setInterconnection(id, swIfIndex, ifcName, vppL2); } - private void setInterconnection(final InstanceIdentifier<L2> id, final int swIfIndex, final Interface ifc, + private void setInterconnection(final InstanceIdentifier<L2> id, final int swIfIndex, final String ifcName, final L2 vppL2) throws VppApiInvocationException, WriteFailedException { Interconnection ic = vppL2.getInterconnection(); if (ic instanceof XconnectBased) { - setXconnectBasedL2(swIfIndex, ifc, (XconnectBased) ic); + setXconnectBasedL2(swIfIndex, ifcName, (XconnectBased) ic); } else if (ic instanceof BridgeBased) { - setBridgeBasedL2(swIfIndex, ifc, (BridgeBased) ic); + setBridgeBasedL2(swIfIndex, ifcName, (BridgeBased) ic); } else { // FIXME how does choice extensibility work // FIXME it is not even possible to create a dedicated customizer for Interconnection, since it's not a DataObject @@ -123,16 +119,16 @@ public class L2Customizer extends VppApiCustomizer implements ChildWriterCustomi } } - private void setBridgeBasedL2(final int swIfIndex, final Interface ifc, final BridgeBased bb) + private void setBridgeBasedL2(final int swIfIndex, final String ifcName, final BridgeBased bb) throws VppApiInvocationException { LOG.debug("Setting bridge based interconnection(bridge-domain=%s) for interface: %s", - bb.getBridgeDomain(), ifc.getName()); + bb.getBridgeDomain(), ifcName); String bdName = bb.getBridgeDomain(); int bdId = getVppApi().bridgeDomainIdFromName(bdName); checkArgument(bdId > 0, "Unable to set Interconnection for Interface: %s, bridge domain: %s does not exist", - ifc.getName(), bdName); + ifcName, bdName); byte bvi = bb.isBridgedVirtualInterface() ? (byte) 1 @@ -143,36 +139,36 @@ public class L2Customizer extends VppApiCustomizer implements ChildWriterCustomi final int rv = V3poUtils.waitForResponse(ctxId, getVppApi()); if (rv < 0) { - LOG.warn("Failed to update bridge based interconnection flags for: {}, interconnection: {}", ifc.getName(), + LOG.warn("Failed to update bridge based interconnection flags for: {}, interconnection: {}", ifcName, bb); throw new VppApiInvocationException("swInterfaceSetL2Bridge", ctxId, rv); } else { - LOG.debug("Bridge based interconnection updated successfully for: {}, interconnection: {}", ifc.getName(), + LOG.debug("Bridge based interconnection updated successfully for: {}, interconnection: {}", ifcName, bb); } } - private void setXconnectBasedL2(final int swIfIndex, final Interface ifc, final XconnectBased ic) + private void setXconnectBasedL2(final int swIfIndex, final String ifcName, final XconnectBased ic) throws VppApiInvocationException { String outSwIfName = ic.getXconnectOutgoingInterface(); LOG.debug("Setting xconnect based interconnection(outgoing ifc=%s) for interface: %s", outSwIfName, - ifc.getName()); + ifcName); int outSwIfIndex = getVppApi().swIfIndexFromName(outSwIfName); checkArgument(outSwIfIndex > 0, "Unable to set Interconnection for Interface: %s, outgoing interface: %s does not exist", - ifc.getName(), outSwIfIndex); + ifcName, outSwIfIndex); int ctxId = getVppApi().swInterfaceSetL2Xconnect(swIfIndex, outSwIfIndex, (byte) 1 /* enable */); final int rv = V3poUtils.waitForResponse(ctxId, getVppApi()); if (rv < 0) { LOG.warn("Failed to update xconnect based interconnection flags for: {}, interconnection: {}", - ifc.getName(), ic); + ifcName, ic); throw new VppApiInvocationException("swInterfaceSetL2Xconnect", ctxId, rv); } else { - LOG.debug("Xconnect based interconnection updated successfully for: {}, interconnection: {}", ifc.getName(), + LOG.debug("Xconnect based interconnection updated successfully for: {}, interconnection: {}", ifcName, ic); } } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/RoutingCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/RoutingCustomizer.java index 8d930d80c..718afc0e1 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/RoutingCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/RoutingCustomizer.java @@ -53,10 +53,9 @@ public class RoutingCustomizer extends VppApiCustomizer implements ChildWriterCu public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Routing> id, @Nonnull final Routing dataAfter, @Nonnull final Context writeContext) throws WriteFailedException.CreateFailedException { - final Interface ifc = (Interface) writeContext.get(InterfaceCustomizer.IFC_AFTER_CTX); try { - setRouting(ifc.getName(), dataAfter); + setRouting(id.firstKeyOf(Interface.class).getName(), dataAfter); } catch (VppApiInvocationException e) { LOG.warn("Update of Routing failed", e); throw new WriteFailedException.CreateFailedException(id, dataAfter, e); @@ -68,12 +67,10 @@ public class RoutingCustomizer extends VppApiCustomizer implements ChildWriterCu @Nonnull final Routing dataBefore, @Nonnull final Routing dataAfter, @Nonnull final Context writeContext) throws WriteFailedException.UpdateFailedException { - final Interface ifcBefore = (Interface) writeContext.get(InterfaceCustomizer.IFC_BEFORE_CTX); - final Interface ifcAfter = (Interface) writeContext.get(InterfaceCustomizer.IFC_BEFORE_CTX); try { // TODO handle updates properly - setRouting(ifcAfter.getName(), dataAfter); + setRouting(id.firstKeyOf(Interface.class).getName(), dataAfter); } catch (VppApiInvocationException e) { LOG.warn("Update of Routing failed", e); throw new WriteFailedException.UpdateFailedException(id, dataBefore, dataAfter, e); diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VppInterfaceCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VppInterfaceCustomizer.java deleted file mode 100644 index 3ea3f9743..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VppInterfaceCustomizer.java +++ /dev/null @@ -1,210 +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.translate.v3po.interfaces; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Optional; -import io.fd.honeycomb.v3po.translate.Context; -import io.fd.honeycomb.v3po.translate.spi.write.ChildWriterCustomizer; -import io.fd.honeycomb.v3po.translate.v3po.util.VppApiCustomizer; -import io.fd.honeycomb.v3po.translate.v3po.util.VppApiInvocationException; -import io.fd.honeycomb.v3po.translate.v3po.utils.V3poUtils; -import io.fd.honeycomb.v3po.translate.write.WriteFailedException; -import javax.annotation.Nonnull; -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.interfaces.rev140508.InterfaceType; -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.VppInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VxlanTunnel; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class VppInterfaceCustomizer extends VppApiCustomizer - implements ChildWriterCustomizer<VppInterfaceAugmentation> { - - private static final Logger LOG = LoggerFactory.getLogger(VppInterfaceCustomizer.class); - - public VppInterfaceCustomizer(final org.openvpp.vppjapi.vppApi vppApi) { - super(vppApi); - } - - @Nonnull - @Override - public Optional<VppInterfaceAugmentation> extract( - @Nonnull final InstanceIdentifier<VppInterfaceAugmentation> currentId, - @Nonnull final DataObject parentData) { - return Optional.fromNullable(((Interface) parentData).getAugmentation(VppInterfaceAugmentation.class)); - } - - @Override - public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<VppInterfaceAugmentation> id, - @Nonnull final VppInterfaceAugmentation dataAfter, - @Nonnull final Context writeContext) - throws WriteFailedException { - final Interface ifc = (Interface) writeContext.get(InterfaceCustomizer.IFC_AFTER_CTX); - try { - setInterface(id, ifc, dataAfter); - } catch (VppApiInvocationException e) { - LOG.warn("Update of VppInterfaceAugment failed", e); - throw new WriteFailedException.CreateFailedException(id, dataAfter, e); - } - } - - @Override - public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<VppInterfaceAugmentation> id, - @Nonnull final VppInterfaceAugmentation dataBefore, - @Nonnull final VppInterfaceAugmentation dataAfter, - @Nonnull final Context writeContext) - throws WriteFailedException.UpdateFailedException { - final Interface ifcBefore = (Interface) writeContext.get(InterfaceCustomizer.IFC_BEFORE_CTX); - final Interface ifc = (Interface) writeContext.get(InterfaceCustomizer.IFC_AFTER_CTX); - try { - updateInterface(id, ifc, dataBefore, dataAfter); - } catch (VppApiInvocationException e) { - LOG.warn("Update of VppInterfaceAugment failed", e); - throw new WriteFailedException.UpdateFailedException(id, dataBefore, dataAfter, e); - } - } - - @Override - public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<VppInterfaceAugmentation> id, - @Nonnull final VppInterfaceAugmentation dataBefore, - @Nonnull final Context writeContext) { - final Interface ifcBefore = (Interface) writeContext.get(InterfaceCustomizer.IFC_BEFORE_CTX); - - LOG.info("Deleting interface: {}, type: {}", ifcBefore.getName(), ifcBefore.getType().getSimpleName()); - - if (ifcBefore.getType().isAssignableFrom(EthernetCsmacd.class)) { - LOG.error("Interface {}, type: {} cannot be deleted", - ifcBefore.getName(), ifcBefore.getType().getSimpleName()); - - /* FIXME: Add additional interface types here. - * - * } else if (swIf.getType().isAssignableFrom(*.class)) { - */ - - } - } - - - private void updateInterface(final InstanceIdentifier<VppInterfaceAugmentation> id, final Interface swIf, - final VppInterfaceAugmentation dataBefore, - final VppInterfaceAugmentation dataAfter) throws VppApiInvocationException { - LOG.info("Updating interface {}, type: {}", swIf.getName(), swIf.getType().getSimpleName()); - LOG.debug("Updating interface {}", swIf); - - Class<? extends InterfaceType> ifType = checkNotNull(swIf.getType(), "Interface type missing for %s", swIf); - String swIfName = swIf.getName(); - int swIfIndex = getVppApi().swIfIndexFromName(swIfName); - checkArgument(swIfIndex != -1, "Updating non-existing vpp interface: %s", swIfName); - - // TODO handle updates properly - - if (VxlanTunnel.class.isAssignableFrom(ifType)) { - updateVxlanTunnelInterface(swIf); - } else if (EthernetCsmacd.class.isAssignableFrom(ifType)) { - updateEthernetCsmacdInterface(swIf, swIfName, swIfIndex); - } - } - - - private void setInterface(final InstanceIdentifier<VppInterfaceAugmentation> id, final Interface swIf, - final VppInterfaceAugmentation dataAfter) - throws VppApiInvocationException, WriteFailedException { - LOG.info("Setting interface {}, type: {}", swIf.getName(), swIf.getType().getSimpleName()); - LOG.debug("Setting interface {}", swIf); - - Class<? extends InterfaceType> ifType = checkNotNull(swIf.getType(), "Interface type missing for %s", swIf); - String swIfName = swIf.getName(); - int swIfIndex = getVppApi().swIfIndexFromName(swIfName); - checkArgument(swIfIndex == -1, "Creating already-existing vpp interface: %s", swIfName); - - if (VxlanTunnel.class.isAssignableFrom(ifType)) { - createVxlanTunnelInterface(swIf, swIfName); - } else if (EthernetCsmacd.class.isAssignableFrom(ifType)) { - createEthernetCsmacdInterface(id, swIfName, dataAfter); - } - } - - private void createVxlanTunnelInterface(final Interface swIf, final String swIfName) - throws VppApiInvocationException { - LOG.debug("Creating {} interface {}", swIf.getType().getSimpleName(), swIf.getName()); - - // FIXME, Vxlan child writer needs to be handled before this is - int newSwIfIndex = getVppApi().swIfIndexFromName(swIfName); - - setInterfaceFlags(swIfName, newSwIfIndex, swIf.isEnabled() - ? (byte) 1 - : (byte) 0); - setDescription(swIf); - } - - private void updateVxlanTunnelInterface(final Interface swIf) { - LOG.debug("Updating {} interface {}", swIf.getType().getSimpleName(), swIf.getName()); - - // TODO handle - } - - private void createEthernetCsmacdInterface(final InstanceIdentifier<VppInterfaceAugmentation> id, - final String swIfName, final VppInterfaceAugmentation dataAfter) throws WriteFailedException { - LOG.warn("Unable to create interface: {}, type: {}", swIfName, EthernetCsmacd.class); - throw new WriteFailedException.CreateFailedException(id, dataAfter); - } - - private void updateEthernetCsmacdInterface(final Interface swIf, - final String swIfName, final int swIfIndex) - throws VppApiInvocationException { - LOG.debug("Updating {} interface {}", swIf.getType().getSimpleName(), swIf.getName()); - byte enabled = swIf.isEnabled() - ? (byte) 1 - : (byte) 0; - setInterfaceFlags(swIfName, swIfIndex, enabled); - setDescription(swIf); - } - - private void setInterfaceFlags(final String swIfName, final int swIfIndex, final byte enabled) - throws VppApiInvocationException { - int ctxId = getVppApi().swInterfaceSetFlags(swIfIndex, enabled, enabled, (byte) 0 /* deleted */); - - LOG.debug("Updating interface flags for: {}, index: {}, enabled: {}, ctxId: {}", swIfName, swIfIndex, - enabled, ctxId); - - final int rv = V3poUtils.waitForResponse(ctxId, getVppApi()); - if (rv < 0) { - LOG.warn("Failed to update interface flags for: {}, index: {}, enabled: {}, ctxId: {}", swIfName, swIfIndex, - enabled, ctxId); - throw new VppApiInvocationException("swInterfaceSetFlags", ctxId, rv); - } else { - LOG.debug("Interface flags updated successfully for: {}, index: {}, enabled: {}, ctxId: {}", - swIfName, swIfIndex, enabled, ctxId); - } - } - - private void setDescription(final Interface swIf) { - if (swIf.getDescription() != null) { - getVppApi().setInterfaceDescription(swIf.getName(), swIf.getDescription()); - } else { - getVppApi().setInterfaceDescription(swIf.getName(), ""); - } - } - -} - diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VxlanCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VxlanCustomizer.java index 2b2774ece..dbf8cb0c7 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VxlanCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VxlanCustomizer.java @@ -18,9 +18,9 @@ package io.fd.honeycomb.v3po.translate.v3po.interfaces; import com.google.common.base.Optional; import io.fd.honeycomb.v3po.translate.Context; -import io.fd.honeycomb.v3po.translate.v3po.util.VppApiInvocationException; import io.fd.honeycomb.v3po.translate.spi.write.ChildWriterCustomizer; import io.fd.honeycomb.v3po.translate.v3po.util.VppApiCustomizer; +import io.fd.honeycomb.v3po.translate.v3po.util.VppApiInvocationException; import io.fd.honeycomb.v3po.translate.v3po.utils.V3poUtils; import io.fd.honeycomb.v3po.translate.write.WriteFailedException; import javax.annotation.Nonnull; @@ -54,9 +54,8 @@ public class VxlanCustomizer extends VppApiCustomizer implements ChildWriterCust public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Vxlan> id, @Nonnull final Vxlan dataAfter, @Nonnull final Context writeContext) throws WriteFailedException.CreateFailedException { - final Interface ifc = (Interface) writeContext.get(InterfaceCustomizer.IFC_AFTER_CTX); try { - createVxlanTunnel(ifc.getName(), dataAfter); + createVxlanTunnel(id.firstKeyOf(Interface.class).getName(), dataAfter); } catch (VppApiInvocationException e) { LOG.warn("Write of Vxlan failed", e); throw new WriteFailedException.CreateFailedException(id, dataAfter, e); @@ -67,12 +66,10 @@ public class VxlanCustomizer extends VppApiCustomizer implements ChildWriterCust public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<Vxlan> id, @Nonnull final Vxlan dataBefore, @Nonnull final Vxlan dataAfter, @Nonnull final Context writeContext) throws WriteFailedException.UpdateFailedException { - final Interface ifcBefore = (Interface) writeContext.get(InterfaceCustomizer.IFC_BEFORE_CTX); - final Interface ifcAfter = (Interface) writeContext.get(InterfaceCustomizer.IFC_BEFORE_CTX); // TODO handle update in a better way try { - createVxlanTunnel(ifcAfter.getName(), dataAfter); + createVxlanTunnel(id.firstKeyOf(Interface.class).getName(), dataAfter); } catch (VppApiInvocationException e) { LOG.warn("Update of L2 failed", e); throw new WriteFailedException.UpdateFailedException(id, dataBefore, dataAfter, e); @@ -82,7 +79,6 @@ public class VxlanCustomizer extends VppApiCustomizer implements ChildWriterCust @Override public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Vxlan> id, @Nonnull final Vxlan dataBefore, @Nonnull final Context writeContext) { - final Interface ifcBefore = (Interface) writeContext.get(InterfaceCustomizer.IFC_BEFORE_CTX); // TODO handle delete } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/ip/Ipv4Customizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/ip/Ipv4Customizer.java index 08974fe68..8349ebb9b 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/ip/Ipv4Customizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/ip/Ipv4Customizer.java @@ -22,7 +22,6 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.base.Optional; import io.fd.honeycomb.v3po.translate.Context; import io.fd.honeycomb.v3po.translate.spi.write.ChildWriterCustomizer; -import io.fd.honeycomb.v3po.translate.v3po.interfaces.InterfaceCustomizer; import io.fd.honeycomb.v3po.translate.v3po.util.VppApiCustomizer; import io.fd.honeycomb.v3po.translate.v3po.util.VppApiInvocationException; import io.fd.honeycomb.v3po.translate.v3po.utils.V3poUtils; @@ -59,10 +58,9 @@ public class Ipv4Customizer extends VppApiCustomizer implements ChildWriterCusto public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Ipv4> id, @Nonnull final Ipv4 dataAfter, @Nonnull final Context writeContext) throws WriteFailedException { - final Interface ifc = (Interface) writeContext.get(InterfaceCustomizer.IFC_AFTER_CTX); - try { - setIpv4(id, ifc.getName(), dataAfter); + final String ifcName = id.firstKeyOf(Interface.class).getName(); + setIpv4(id, ifcName, dataAfter); } catch (VppApiInvocationException e) { LOG.warn("Create of Ipv4 failed", e); throw new WriteFailedException.CreateFailedException(id, dataAfter, e); @@ -74,12 +72,11 @@ public class Ipv4Customizer extends VppApiCustomizer implements ChildWriterCusto @Nonnull final Ipv4 dataBefore, @Nonnull final Ipv4 dataAfter, @Nonnull final Context writeContext) throws WriteFailedException { - final Interface ifcBefore = (Interface) writeContext.get(InterfaceCustomizer.IFC_BEFORE_CTX); - final Interface ifcAfter = (Interface) writeContext.get(InterfaceCustomizer.IFC_BEFORE_CTX); + final String ifcName = id.firstKeyOf(Interface.class).getName(); // TODO handle update in a better way try { - setIpv4(id, ifcAfter.getName(), dataAfter); + setIpv4(id, ifcName, dataAfter); } catch (VppApiInvocationException e) { LOG.warn("Update of Ipv4 failed", e); throw new WriteFailedException.UpdateFailedException(id, dataBefore, dataAfter, e); diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/BridgeDomainCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/BridgeDomainCustomizer.java index e0c193f89..61c345b44 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/BridgeDomainCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/BridgeDomainCustomizer.java @@ -59,13 +59,16 @@ public final class BridgeDomainCustomizer extends VppApiCustomizer id, builder, context); final BridgeDomainKey key = id.firstKeyOf(id.getTargetType()); - // TODO find out if bd exists based on name and if not return LOG.debug("vppstate.BridgeDomainCustomizer.readCurrentAttributes: key={}", key); final int bdId = getVppApi().bridgeDomainIdFromName(key.getName()); LOG.debug("vppstate.BridgeDomainCustomizer.readCurrentAttributes: bdId={}", bdId); final vppBridgeDomainDetails bridgeDomainDetails = getVppApi().getBridgeDomainDetails(bdId); + if(bridgeDomainDetails == null) { + LOG.debug("Bridge domain name={} does not exist", key.getName()); + return; + } logBridgeDomainDetails(bridgeDomainDetails); builder.setName(key.getName()); |