/**
*
*/
package com.lgnortel.r4.r4equipment.management.olt.Interface.BundleEther;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.w3c.dom.NamedNodeMap;
import com.lgnortel.lib.logger.LoggerUtil;
import com.lgnortel.netconf.DOM4Confspec;
import com.lgnortel.netconf.NetconfElementModel;
import com.lgnortel.netconf.wdmpon.BundleEtherSpanningTree;
import com.lgnortel.netconf.wdmpon.Jinterface;
import com.lgnortel.netconf.wdmpon.JinterfaceBundleEther;
import com.lgnortel.netconf.wdmpon.Msp;
import com.lgnortel.netconf.wdmpon.SpanningTreeInstance;
import com.lgnortel.r4.r4equipment.common.ManagementComplexModelIF;
import com.lgnortel.r4.r4equipment.common.ParameterCheckException;
import com.lgnortel.r4.util.R4Constants;
import com.lgnortel.r4.util.R4Util;
import com.tailf.inm.Element;
import com.tailf.inm.ElementChildrenIterator;
/**
* Copyright (c) 2009 LG-Nortel, Inc. All Rights Reserved.
*
* CONFIDENTIALITY AND LIMITED USE: This software, including any software of <br>
* third parties embodied herein, contains code, information, data and concepts <br>
* which are confidential and/or proprietary to LG-Nortel and such third <br>
* parties. This software is licensed for use solely in accordance with the <br>
* terms and conditions of the applicable license agreement with LG-Nortel or <br>
* its authorized distributor, and not for any other use or purpose. No <br>
* redistribution of this software by any party is permitted. <br>
*
* Title: InterfaceBundleEtherSpanningTreeInstanceModel<br>
* Description: <br>
* Copyright: Copyright(c) 2009 LG-NORTEL ALL Rights Reserved<br>
* Company: LG-Nortel<br>
*
* @author Sungill, Kim
* @version 0.1
* @created 2009. 6. 25.
* @modified 2009. 6. 25.
* @product EFA R4.0 EMS
* @sw_block
*/
public class InterfaceBundleEtherSpanningTreeInstanceModel implements ManagementComplexModelIF {
// Log4J
Logger logger = LoggerUtil.getInstance().getLogger(this.getClass().getName());
public static final String TABLE_NAME = "Interface Bundle-Ether STP Instance";
// Syntax information
String sMaxOccurs = null;
// Column Definition
private String COLUMN_NAME_BUNDLE_ETHER_ID = "bundle-id"; // BundleEther table's key
private String COLUMN_NAME_INSTANCE_ID = "instance-id";
private String COLUMN_NAME_COST = "cost";
private String COLUMN_NAME_PORT_PRIORITY = "port-priority";
/**
* Constructor
*
* @param neId
*/
public InterfaceBundleEtherSpanningTreeInstanceModel() {
}
/**
* Return table schema information
*/
public List<NetconfElementModel> getTableSchema() {
Vector<NetconfElementModel> columnInfo = new Vector<NetconfElementModel>();
// Locate "msp/interface/Ethernet" Node in the DOM tree of wdmpon.cs
DOM4Confspec dom4Confspec = DOM4Confspec.getInstance();
String[] fdn = {"msp", "interface", "Bundle-Ether", "spanning-tree", "instance"};
org.w3c.dom.Node node = dom4Confspec.findNode(fdn);
if (node == null) {
logger.warning("wdmpon.cs parsing error!");
return null;
}
// extract and save 'maxOccurs' value for getMaxOccurs()
NamedNodeMap nnm = node.getAttributes();
org.w3c.dom.Node itemNode = nnm.getNamedItem("maxOccurs");
if (itemNode != null) {
sMaxOccurs = itemNode.getNodeValue();
logger.info("sMaxOccurs: " + sMaxOccurs);
}
// Retrieve all attributes of Ethernet component
columnInfo = dom4Confspec.getComponentSchema(node.getChildNodes());
// change column name and width
for (NetconfElementModel oneNem : columnInfo) {
if (oneNem.getElementName().equals("instance")) {
oneNem.setElementName(COLUMN_NAME_INSTANCE_ID);
}
}
return columnInfo;
}
/**
* Return maxOccurs value of msp/interface/Bundle-Ether/spanning-tree/instance Component
*/
public int getMaxOccurs() {
int maxOccurs = 1;
if (sMaxOccurs != null) {
if (sMaxOccurs.equals(R4Constants.MAX_OCCURS_VALUE_UNBOUNDED)) {
maxOccurs = Integer.MAX_VALUE;
} else {
maxOccurs = Integer.parseInt(sMaxOccurs);
}
}
return maxOccurs;
}
/**
* Make Filter from Msp MO
*/
public Element getFilter() {
Msp filter = new Msp();
try {
filter.addJinterface().addBundleEther().addSpanningTree().addInstance();
} catch (Exception e) {
logger.log(Level.SEVERE, "Exception", e);
}
return filter;
}
/**
* Convert Element into the form that can be used in Table Model
* ===================================================
* instance cost port-priority
* stp-instance-type xs:int stp-port-priority-type
* ---------------------------------------------------
* 1 10 0
* 2 20 16
* 3 30 32
* ===================================================
*/
public Vector<Vector<Object>> makeTableInformation(Element element, Map<String, Object> keys) {
// save parent MO's key
Object bundleEtherId = keys.get(COLUMN_NAME_BUNDLE_ETHER_ID);
if (bundleEtherId == null) {
logger.warning("makeTableInformation().. error in keys.. there should be '" + COLUMN_NAME_BUNDLE_ETHER_ID + "' key!");
return null;
}
logger.info("makeTableInformation() under msp/interface/Bundle-Ether['" + bundleEtherId + "']..");
// return value
Vector<Vector<Object>> tblInfo = new Vector<Vector<Object>>();
try {
// Locate msp/interface/Bundle-Ether/spanning-tree MO
Msp msp = (Msp) element;
Jinterface mspIf = msp.jinterface;
if (mspIf == null) {
logger.info("No interface configuration..");
return tblInfo;
}
JinterfaceBundleEther bundleEther = null;
try {
bundleEther = mspIf.getBundleEther(bundleEtherId.toString());
} catch (Exception e) {
logger.info("No interface/Bundle-Ether['" + bundleEtherId + "'] configuration..");
return tblInfo;
}
BundleEtherSpanningTree stp = bundleEther.spanningTree;
if (stp == null) {
logger.info("No interface/Bundle-Ether['" + bundleEtherId + "']/spanning-tree configuration..");
return tblInfo;
}
// Get spanning-tree/instance MO list from stp MO
ElementChildrenIterator stpInstanceIt = stp.instanceIterator();
while (stpInstanceIt.hasNext()) {
// spanning-tree/instance MO
SpanningTreeInstance stpInstance = (SpanningTreeInstance) stpInstanceIt.next();
// Extract attribute value
Object instance = R4Util.validateNullValue(stpInstance.getInstanceValue());
Object cost = R4Util.validateNullValue(stpInstance.getCostValue());
Object portPriority = R4Util.validateNullValue(stpInstance.getPortPriorityValue());
// make results
Vector<Object> tblRow = new Vector<Object>();
tblRow.addElement(instance);
tblRow.addElement(cost);
tblRow.addElement(portPriority);
// add a row into the table
tblInfo.addElement(tblRow);
}
} catch (Exception e) {
logger.log(Level.SEVERE, "Exception", e);
}
// return table information
return tblInfo;
}
/**
* Construct MO tree & request 'NETCONF-AUDIT' command
* ===================================================
* instance cost port-priority
* stp-instance-type xs:int stp-port-priority-type
* ---------------------------------------------------
* 1 10 0
* 2 20 16
* 3 30 32
* ===================================================
* @throws ParameterCheckException
*/
public Msp addTableInfoToMsp(Msp msp, List<Map<String, Object>> rows, Map<String, Object> keys) throws ParameterCheckException {
// save parent MO's key
Object bundleEtherId = keys.get(COLUMN_NAME_BUNDLE_ETHER_ID);
if (bundleEtherId == null) {
logger.warning("addTableInfoToMsp().. error in keys.. there should be '" + COLUMN_NAME_BUNDLE_ETHER_ID + "' key!");
return null;
}
try {
// Locate msp/interface/Bundle-Ether/spanning-tree MO
Jinterface mspIf = msp.jinterface;
if (mspIf == null) {
logger.info("No interface configuration..");
mspIf = new Jinterface();
msp.addJinterface(mspIf);
}
JinterfaceBundleEther bundleEther = null;
try {
bundleEther = mspIf.getBundleEther(bundleEtherId.toString());
} catch (Exception e) {
logger.info("No interface/Bundle-Ether['" + bundleEtherId + "'] configuration..");
bundleEther = new JinterfaceBundleEther(bundleEtherId.toString());
mspIf.addBundleEther(bundleEther);
}
BundleEtherSpanningTree stp = bundleEther.spanningTree;
if (stp == null) {
logger.info("No interface/Bundle-Ether['" + bundleEtherId + "']/spanning-tree configuration..");
stp = new BundleEtherSpanningTree();
bundleEther.addSpanningTree(stp);
}
for (int i=0; i<rows.size(); i++) {
Map<String, Object> oneRow = rows.get(i);
// save input argument(oneRow) into variables
String instance = oneRow.get(COLUMN_NAME_INSTANCE_ID).toString();
String cost = oneRow.get(COLUMN_NAME_COST).toString();
String portPriority = oneRow.get(COLUMN_NAME_PORT_PRIORITY).toString();
// Make spanning-tree instance
SpanningTreeInstance stpInstance = new SpanningTreeInstance(instance);
if (R4Util.isExistingField(cost)) {
stpInstance.setCostValue(cost);
}
if (R4Util.isExistingField(portPriority)) {
stpInstance.setPortPriorityValue(portPriority);
}
// attach it under parent
stp.addInstance(stpInstance);
}
} catch (Exception e) {
logger.log(Level.SEVERE, "Exception in set()", e);
throw new ParameterCheckException("Parameter Check Error", "Parameter Check Error");
}
logger.fine("config ==> \n" + msp.toXMLString());
return msp;
}
}
|