/**
*
*/
package com.lgnortel.r4.r4equipment.management.ont.Interface.vlan;
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.Msp;
import com.lgnortel.netconf.wdmpon.Ont;
import com.lgnortel.netconf.wdmpon.OntJinterface;
import com.lgnortel.netconf.wdmpon.OntJinterfaceVlan;
import com.lgnortel.netconf.wdmpon.PonAccess;
import com.lgnortel.netconf.wdmpon.VlanIpv4;
import com.lgnortel.r4.r4equipment.common.ManagementComplexModelIF;
import com.lgnortel.r4.util.R4Constants;
import com.lgnortel.r4.util.R4Util;
import com.tailf.inm.Element;
import com.tailf.inm.INMException;
/**
* 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: OntInterfaceVlanIpv4AddressModel<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. 7. 9.
* @modified 2009. 7. 9.
* @product EFA R4.0 EMS
* @sw_block
*/
public class OntInterfaceVlanIpv4AddressModel implements ManagementComplexModelIF {
// Log4J
Logger logger = LoggerUtil.getInstance().getLogger(this.getClass().getName());
// table name
public static final String TABLE_NAME = "ONT Interface Vlan Address";
// Syntax information
String sMaxOccurs = null;
// Column Definition
private String COLUMN_NAME_ONT_NAME = "name"; // ONT table's key
private String COLUMN_NAME_VLAN_ID = "vlan-id"; // vlan table's key
private String COLUMN_NAME_ADDRESS = "address";
private String COLUMN_NAME_GATEWAY = "gateway";
/**
* Constructor
*/
public OntInterfaceVlanIpv4AddressModel() {
}
/**
* Return table schema information
*/
public List<NetconfElementModel> getTableSchema() {
Vector<NetconfElementModel> columnInfo = new Vector<NetconfElementModel>();
// 1. Locate "msp/pon-access/ont/interface/Ethernet" Node in the DOM tree of wdmpon.cs
DOM4Confspec dom4Confspec = DOM4Confspec.getInstance();
String[] fdn = {"msp", "pon-access", "ont", "interface", "vlan", "ipv4"};
org.w3c.dom.Node node = dom4Confspec.findNode(fdn);
if (node == null) {
logger.warning("wdmpon.cs parsing error!");
return null;
}
// 2. 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);
}
// 3. Extract leaf nodes' attribute information with 'type' attribute
columnInfo = dom4Confspec.getComponentSchema(node.getChildNodes());
return columnInfo;
}
/**
* Return maxOccurs value of msp/pon-access/ont/interface/vlan/ipv4 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
*
* @return
*/
public Element getFilter() {
// construct filter to retrieve msp/pon-access/ont/interface/vlan/ipv4 MOs only
Msp filter = new Msp();
try {
filter.addPonAccess().addOnt().addJinterface().addVlan().addIpv4();
} catch (Exception e) {
logger.log(Level.SEVERE, "Exception", e);
}
return filter;
}
/**
* Convert Element into the form that can be used in Table Model
* ==============================================
* address gateway
* ipPrefix-dhcp-union-type ipv4-address-type
* ----------------------------------------------
* 1.1.1.1 1.1.1.10
* 1.1.1.2 1.1.1.11
* 1.1.1.3 1.1.1.12
* ==============================================
*/
public Vector<Vector<Object>> makeTableInformation(Element element, Map<String, Object> keys) {
// return value
Vector<Vector<Object>> tblInfo = new Vector<Vector<Object>>();
Object ontName = keys.get(COLUMN_NAME_ONT_NAME);
if (ontName == null) {
logger.warning("makeTableInformation(): error in keys.. there should be '" + COLUMN_NAME_ONT_NAME + "' key!");
return tblInfo;
}
Object vlanId = keys.get(COLUMN_NAME_VLAN_ID);
if (ontName == null) {
logger.warning("makeTableInformation(): error in keys.. there should be '" + COLUMN_NAME_VLAN_ID + "' key!");
return tblInfo;
}
logger.info("makeTableInformation(): under ONT['" + ontName + "']/interface/vlan['" + vlanId + "']/ipv4");
try {
// 1. Locate msp/pon-access/ont/interface/vlan/ipv4 MO
Msp msp = (Msp) element;
PonAccess ponAccess = msp.ponAccess;
if (ponAccess == null) {
logger.info("No pon-access configuration..");
return tblInfo;
}
Ont ont = null;
try {
ont = ponAccess.getOnt(ontName.toString());
} catch (INMException ie) {
logger.info("No pon-access/ont['" + ontName + "'] configuration..");
return tblInfo;
}
OntJinterface ontIf = ont.jinterface;
if (ontIf == null) {
logger.info("No pon-access/ont['" + ontName + "']/interface configuration..");
return tblInfo;
}
OntJinterfaceVlan vlan = null;
try {
vlan = ontIf.getVlan(vlanId.toString());
} catch (INMException ie) {
logger.info("No pon-access/ont['" + ontName + "']/interface/vlan['" + vlanId + "'] configuration..");
return tblInfo;
}
VlanIpv4 ipv4 = vlan.ipv4;
if (ipv4 == null) {
logger.info("No pon-access/ONT['" + ontName + "']/interface/vlan['" + vlanId + "']/ipv4 configuration..");
return tblInfo;
}
// Extract attribute value
Object address = R4Util.validateNullValue(ipv4.getAddressValue());
Object gateway = R4Util.validateNullValue(ipv4.getGatewayValue());
// Make a row
Vector<Object> tblRow = new Vector<Object>();
tblRow.addElement(address);
tblRow.addElement(gateway);
// add to table
tblInfo.addElement(tblRow);
} catch (Exception e) {
logger.log(Level.SEVERE, "Exception in makeTableInformation()", e);
}
// return table information
return tblInfo;
}
/**
* Construct MO tree & request 'NETCONF-AUDIT' command
* ==============================================
* address gateway
* ipPrefix-dhcp-union-type ipv4-address-type
* ----------------------------------------------
* 1.1.1.1 1.1.1.10
* 1.1.1.2 1.1.1.11
* 1.1.1.3 1.1.1.12
* ==============================================
*/
public Msp addTableInfoToMsp(Msp msp, List<Map<String, Object>> rows, Map<String, Object> keys) {
Object ontName = keys.get(COLUMN_NAME_ONT_NAME);
if (ontName == null) {
logger.warning("addTableInfoToMsp(): error in keys.. there should be '" + COLUMN_NAME_ONT_NAME + "' key!");
return msp;
}
Object vlanId = keys.get(COLUMN_NAME_VLAN_ID);
if (vlanId == null) {
logger.warning("makeTableInformation(): error in keys.. there should be '" + COLUMN_NAME_VLAN_ID + "' key!");
return msp;
}
logger.info("addTableInfoToMsp(): under ONT['" + ontName + "']/interface/vlan['" + vlanId + "']");
try {
// 1. Locate msp/pon-access/ont/interface/vlan/ipv4
PonAccess ponAccess = msp.ponAccess;
if (ponAccess == null) {
logger.info("No pon-access configuration..");
ponAccess = new PonAccess();
msp.addPonAccess(ponAccess);
}
Ont ont = null;
try {
ont = ponAccess.getOnt(ontName.toString());
} catch (INMException ie) {
logger.info("No pon-access/ont['" + ontName + "'] configuration..");
ont = new Ont(ontName.toString());
ponAccess.addOnt(ont);
}
OntJinterface ontIf = ont.jinterface;
if (ontIf == null) {
logger.info("No pon-access/ont'" + ontName + "']/interface configuration..");
ontIf = new OntJinterface();
ont.addJinterface(ontIf);
}
OntJinterfaceVlan vlan = null;
try {
vlan = ontIf.getVlan(vlanId.toString());
// clean up ipv4
vlan.delete("ipv4");
} catch (INMException ie) {
logger.info("No pon-access/ont['" + ontName + "']/interface/vlan['" + vlanId + "'] configuration..");
vlan = new OntJinterfaceVlan(vlanId.toString());
ontIf.addVlan(vlan);
}
// 2. construct MO tree
for (int i=0; i<rows.size(); i++) {
Map<String, Object> oneRow = rows.get(i);
// input argument(oneRow)
String address = oneRow.get(COLUMN_NAME_ADDRESS).toString();
String gateway = oneRow.get(COLUMN_NAME_GATEWAY).toString();
// Make ONT/interface/vlan/ipv4
VlanIpv4 ipv4 = new VlanIpv4();
if (R4Util.isExistingField(address)) {
ipv4.setAddressValue(address);
}
if (R4Util.isExistingField(gateway)) {
ipv4.setGatewayValue(gateway);
}
// append it under parent MO
vlan.addIpv4(ipv4);
}
} catch (Exception e) {
logger.log(Level.SEVERE, "Exception in set()", e);
return null;
}
logger.fine("config ==> \n" + msp.toXMLString());
return msp;
}
}
|