/** * Return the VTN configuration in the given VTN. * * @param vnode The VTN container. * @return The configuration for the given VTN. */ @Override protected VtenantConfig getConfig(Vtn vnode) { return vnode.getVtenantConfig(); }
public Vtn build() { return new VtnImpl(this); }
public VtnBuilder addAugmentation(java.lang.Class<? extends Augmentation<org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.rev150328.vtns.Vtn>> augmentationType, Augmentation<org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.rev150328.vtns.Vtn> augmentation) { if (augmentation == null) { return removeAugmentation(augmentationType); } if (!(this.augmentation instanceof HashMap)) { this.augmentation = new HashMap<>(); } this.augmentation.put(augmentationType, augmentation); return this; }
public VtnBuilder(Vtn base) { if (base.getKey() == null) { this._key = new VtnKey( base.getName() ); this._name = base.getName(); } else { this._key = base.getKey(); this._name = _key.getName(); } this._vbridge = base.getVbridge(); this._vtenantConfig = base.getVtenantConfig(); this._vterminal = base.getVterminal(); this._vtnInputFilter = base.getVtnInputFilter(); this._vtnPathMaps = base.getVtnPathMaps(); if (base instanceof VtnImpl) { VtnImpl impl = (VtnImpl) base; if (!impl.augmentation.isEmpty()) { this.augmentation = new HashMap<>(impl.augmentation); } } else if (base instanceof AugmentationHolder) { @SuppressWarnings("unchecked") AugmentationHolder<org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.rev150328.vtns.Vtn> casted =(AugmentationHolder<org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.rev150328.vtns.Vtn>) base; if (!casted.augmentations().isEmpty()) { this.augmentation = new HashMap<>(casted.augmentations()); } } }
private VtnImpl(VtnBuilder base) { if (base.getKey() == null) { this._key = new VtnKey( base.getName() ); this._name = base.getName(); } else { this._key = base.getKey(); this._name = _key.getName(); } this._vbridge = base.getVbridge(); this._vtenantConfig = base.getVtenantConfig(); this._vterminal = base.getVterminal(); this._vtnInputFilter = base.getVtnInputFilter(); this._vtnPathMaps = base.getVtnPathMaps(); switch (base.augmentation.size()) { case 0: this.augmentation = Collections.emptyMap(); break; case 1: final Map.Entry<java.lang.Class<? extends Augmentation<org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.rev150328.vtns.Vtn>>, Augmentation<org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.rev150328.vtns.Vtn>> e = base.augmentation.entrySet().iterator().next(); this.augmentation = Collections.<java.lang.Class<? extends Augmentation<org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.rev150328.vtns.Vtn>>, Augmentation<org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.rev150328.vtns.Vtn>>singletonMap(e.getKey(), e.getValue()); break; default : this.augmentation = new HashMap<>(base.augmentation); } }
/** * Return an instance identifier builder which contains the VTN key. * * @return An instance identifier builder. */ protected final InstanceIdentifierBuilder<Vtn> getVtnIdentifierBuilder() { return InstanceIdentifier.builder(Vtns.class). child(Vtn.class, new VtnKey(tenantName)); }
/** * Determine whether the specified VTN contains at least one vBridge or * not. * * @param tname The name of the VTN. * @return True is returned on successful completion, else false is returned. */ public boolean hasBridge(String tname) { Vtn opt = mdSal.read(LogicalDatastoreType.OPERATIONAL, getTenantPath(tname)); boolean ret; if (opt != null) { List<Vbridge> vbridges = opt.getVbridge(); ret = (vbridges != null && !vbridges.isEmpty()); } else { ret = false; } return ret; }
/** * Record a log message that indicates the VTN has been created or removed. * * @param vtn A {@link Vtn} instance. * @param type {@link VtnUpdateType#CREATED} on created. * {@link VtnUpdateType#REMOVED} on removed. */ private void log(Vtn vtn, VtnUpdateType type) { if (LOG.isInfoEnabled()) { VTenantIdentifier vtnId = new VTenantIdentifier(vtn.getName()); LOG.info("{}: VTN has been {}: value={{}}", vtnId, MiscUtils.toLowerCase(type), toString(vtn.getVtenantConfig())); } }
/** * Construct a new instance. * * @param pctx A runtime context for a received packet. * @param vtnId The identifier of the VTN. * @param vtn A {@link Vtn} instance read from the MD-SAL datastore. */ public VTenant(PacketContext pctx, VTenantIdentifier vtnId, Vtn vtn) { super(vtnId, vtn); // Initialize flow timeout. VtenantConfig cfg = vtn.getVtenantConfig(); pctx.setFlowTimeout(cfg.getIdleTimeout(), cfg.getHardTimeout()); // Initialize VTN input filter. inputFilter = getFlowFilterList( pctx.getTxContext(), false, vtn.getVtnInputFilter()); }
/** * Record the given VTN tree for saving configuration. * * @param ectx A {@link VTenantChange} instance. * @param data A {@link IdentifiedData} instance that contains a * VTN data tree. * @param created {@code true} indicates that the given VTN has been * created. * @return The VTN in {@code data}. */ private Vtn onChanged(VTenantChange ectx, IdentifiedData<?> data, boolean created) { IdentifiedData<Vtn> cdata = cast(data); Vtn vtn = cdata.getValue(); String name = vtn.getName().getValue(); ectx.addUpdatedVtn(name, vtn, created); return vtn; }
/** * Create a new VTN. * * @param ctx A runtime context for transaction task. * @param ident The identifier for the new VTN. * @param cfg The configuration for the new VTN. * @throws VTNException An error occurred. */ @Override protected void create(TxContext ctx, VTenantIdentifier ident, VtenantConfig cfg) throws VTNException { // Create a new VTN. Vtn vtn = new VtnBuilder(). setName(ident.getTenantName()). setVtenantConfig(cfg). build(); ReadWriteTransaction tx = ctx.getReadWriteTransaction(); LogicalDatastoreType oper = LogicalDatastoreType.OPERATIONAL; tx.put(oper, ident.getIdentifier(), vtn, true); // Prepare a list of MAC address tables for a new VTN. InstanceIdentifier<TenantMacTable> mpath = getTenantMacTablePath(ident); TenantMacTable mtable = new TenantMacTableBuilder(). setName(ident.getTenantNameString()). build(); tx.put(oper, mpath, mtable, true); }
/** * Fetch the VTN name from the given path argument, and set it into * {@code VNodePathConverter} instance. * * @param conv A {@link VNodePathConverter} instance. * @param arg A path argument which contains the VTN name. */ @Override public void fetch(VNodePathConverter conv, PathArgument arg) { @SuppressWarnings("unchecked") IdentifiableItem<Vtn, VtnKey> item = (IdentifiableItem<Vtn, VtnKey>)arg; conv.tenantName = item.getKey().getName(); }
/** * Return an instance identifier that specifies the VTN. * * @param tname The name of the VTN. * @return An {@link InstanceIdentifier} instance. */ public static InstanceIdentifier<Vtn> getTenantPath(String tname) { VtnKey vtnKey = new VtnKey(new VnodeName(tname)); return InstanceIdentifier.builder(Vtns.class) .child(Vtn.class, vtnKey) .build(); }
/** * Determine whether the specified VTN contains at least one vBridge or * not. * * @param tname The name of the VTN. * @return {@code true} if the specified VTN contains at least one * vBridge. {@code false} otherwise. */ public boolean hasBridge(String tname) { LogicalDatastoreType oper = LogicalDatastoreType.OPERATIONAL; Optional<Vtn> opt = mdSal.read(oper, getTenantPath(tname)); boolean ret; if (opt.isPresent()) { List<Vbridge> vbridges = opt.get().getVbridge(); ret = (vbridges != null && !vbridges.isEmpty()); } else { ret = false; } return ret; }
/** * {@inheritDoc} */ @Override void onRemoved(VTenantChange ectx, IdentifiedData<?> data) { IdentifiedData<Vtn> cdata = cast(data); Vtn vtn = cdata.getValue(); String name = vtn.getName().getValue(); ectx.addRemoved(name); log(vtn, VtnUpdateType.REMOVED); }
/** * Create a brief description about the path map specified by the given * instance identifier. * * @param path The path to the path map. * @return A brief description about the specified path map. */ private static String getDescription(InstanceIdentifier<VtnPathMap> path) { VtnKey key = path.firstKeyOf(Vtn.class); String desc; if (key == null) { desc = "Global"; } else { VTenantIdentifier vtnId = new VTenantIdentifier(key.getName()); desc = vtnId.toString() + ": VTN"; } return desc; } }
/** * Return an instance identifier that specifies the VTN. * * @param tname The name of the VTN. * @return An {@link InstanceIdentifier} instance. */ public static InstanceIdentifier<Vtn> getTenantPath(String tname) { VtnKey vtnKey = new VtnKey(new VnodeName(tname)); return InstanceIdentifier.builder(Vtns.class). child(Vtn.class, vtnKey). build(); }
/** * Return the identifier for the vBridge in the specified data. * * @param data An {@link IdentifiedData} instance. * Note that this must contain a vBridge or a child node * inside vBridge. * @return A {@link VBridgeIdentifier} instance. */ private static VBridgeIdentifier getVBridgeIdentifier( IdentifiedData<?> data) { InstanceIdentifier<?> path = data.getIdentifier(); VnodeName tname = path.firstKeyOf(Vtn.class).getName(); VnodeName bname = path.firstKeyOf(Vbridge.class).getName(); return new VBridgeIdentifier(tname, bname); }
/** * Return an instance identifier that specifies the vBridge configuration. * * @param tname The name of the VTN. * @param bname The name of the vBridge. * @return An {@link InstanceIdentifier} instance. */ public static InstanceIdentifier<VbridgeConfig> getBridgeConfigPath( String tname, String bname) { VtnKey vtnKey = new VtnKey(new VnodeName(tname)); VbridgeKey vbrKey = new VbridgeKey(new VnodeName(bname)); return InstanceIdentifier.builder(Vtns.class). child(Vtn.class, vtnKey). child(Vbridge.class, vbrKey). child(VbridgeConfig.class). build(); }
/** * Return an instance identifier that specifies the vBridge configuration. * * @param tname The name of the VTN. * @param bname The name of the vBridge. * @return An {@link InstanceIdentifier} instance. */ public static InstanceIdentifier<VbridgeConfig> getBridgeConfigPath( String tname, String bname) { VtnKey vtnKey = new VtnKey(new VnodeName(tname)); VbridgeKey vbrKey = new VbridgeKey(new VnodeName(bname)); return InstanceIdentifier.builder(Vtns.class) .child(Vtn.class, vtnKey) .child(Vbridge.class, vbrKey) .child(VbridgeConfig.class) .build(); }