package com.lgnortel.r3.r3nemanager.r3oam;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import java.util.logging.Logger;
import com.lgnortel.lib.logger.LoggerUtil;
import com.lgnortel.network.networkview.ErrorInspect;
import com.lgnortel.r3.r3nemanager.r3pdu.CommandExcutor;
import com.lgnortel.r3.r3nemanager.r3pdu.MpHeaderInfo;
import com.lgnortel.r3.r3nemanager.r3pdu.MpHeaderPdu;
import com.lgnortel.r3.r3nemanager.r3pdu.NeConstants;
import com.lgnortel.r3.r3rmi.NeOamIF;
/**
* Copyright (c) 2008 LG-Nortel, Inc. All Rights Reserved.
*
* CONFIDENTIALITY AND LIMITED USE: This software, including any software of third parties embodied herein, contains code, information, data and concepts which are confidential and/or proprietary to LG-Nortel and such third parties. This software is licensed for use solely in accordance with the terms and conditions of the applicable license agreement with LG-Nortel or its authorized distributor, and not for any other use or purpose. No redistribution of this software by any party is permitted.
*
*
*<p>
* Title: SetRouteMcu.java
* </p>
*<p>
* Description: The Command Dispatcher in EA Manager 1100 Server processes a command requested from GUI using this class.
* </p>
*<p>
* Copyright: Copyright(c) 2008 LG-NORTEL ALL Rights Reserved
* </p>
*<p>
* Company: LG-Nortel
* </p>
*
*@author OH MOON GUE
*@version 0.1
*@created 2009. 1. 21.
*@modified 2009. 1. 21.
*@product EFA R4.0 EMS
*@sw_block nemanager
*@function_no
*/
public class SetRouteMcu extends CommandExcutor {
/**
* Description: Constructor of this class
*
* @param cmdTag
* : If many clients request with a same command, the command code is equal each other and the cmdTag numbers increase by one.
* @param viewId
* : View ID of GUI
* @param userId
* : Login user ID
* @param nodeId
* : Node ID
* @param shelfId
* : Shelf ID
* @param cmdCode
* : Command code
* @param data
* : A message to be interchanged between EA Manager 1100 GUI and EA Manager 1100 Server
*/
public SetRouteMcu(int cmdTag, int viewId, int userId, int nodeId, int shelfId, int cmdCode, Object[] data) {
this.cmdTag = cmdTag;
this.viewId = viewId;
this.userId = userId;
this.cmdCode = cmdCode;
this.nodeId = nodeId;
this.data = data;
}
/**
* Description: This method hands over a command requested from GUI to the NEIF process to be existed in the MCP board of EAST 1100 and sends a result to perform a command to EA Manager 1100 Server(Command Dispatcher Thread).
*
* @param cmdTag
* : If many clients request with a same command, the command code is equal each other and the cmdTag numbers increase by one.
* @param viewId
* : View ID of GUI
* @param userId
* : Login user ID
* @param nodeId
* : Node ID
* @param shelfId
* : Shelf ID
* @param cmdCode
* : Command code
* @param data
* : A message to be interchanged between EA Manager 1100 GUI and EA Manager 1100 Server
*/
public static void execute(int cmdTag, int viewId, int userId, int nodeId, int shelfId, int cmdCode, Object[] data) {
// Log4J
Logger logger = LoggerUtil.getInstance().getLogger("com.lgnortel.r3.r3nemanager");
String neIpAddr = dbSelecter.getIpAddress(nodeId);
NeOamIF.SetRouteMcuIF inputObject = (NeOamIF.SetRouteMcuIF) data[0];
DatagramSocket socket = null;
byte[] receiveBuffer = new byte[NeConstants.PDU_LENGTH];
MpHeaderInfo headerInfo = null;
if (neIpAddr.equals("") || neIpAddr.length() == 0) {
logger.fine("[SetRouteMcu/execute] Ne ip address is not found!!!"); // DEGUG
cmdDispatcher.cmdResponse(cmdTag, viewId, userId, nodeId, shelfId, cmdCode, data, ErrorInspect.FAILURE);
return;
}
try {
// length
MpHeaderPdu header = new MpHeaderPdu(NeConstants.CODE, NeConstants.PVER, 1, // version
cmdTag, // invokeId
NeConstants.NO_MORE, // moreFlag
0, // seqNo
NeConstants.RTRV_CMD, // cmdType
NeConstants.SEND_CMD, // msgType
NeConstants.NEIF, // channel
shelfId, // sid
userId, neIpAddr, // aganetIp
0, // result
96, // length
cmdCode // commandId
);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream out_stream = new DataOutputStream(baos);
/*
* ===================================================================== [CMD_SET_CONTROL_PATH] ===================================================================== [EMS Server <-> Client] => NeOamIF.java
*
* static public class SetRouteMcuIF implements Serializable { public int nodeId; public int shelfId; public int slotId; public int portId; public int sysType; public int oprtype; public int mask; public String ipaddr; public String subnet; public String gateway; } ===================================================================== struct if_control_path_set_req_com_type { unsigned int objid; unsigned int sid; unsigned int cid; unsigned int lid; unsigned int ontid; enum if_opr_type oprtype; unsigned int mask; char ipaddr[20]; char subnet[20]; char gateway[20]; }; =====================================================================
*/
// write header info
out_stream.write(header.getStream(), 0, NeConstants.HEADER_LENGTH);
out_stream.writeInt(0);
out_stream.writeInt(inputObject.shelfId);
out_stream.writeInt(inputObject.slotId);
out_stream.writeInt(inputObject.portId);
out_stream.writeInt(inputObject.sysType);
out_stream.writeInt(inputObject.oprtype);
out_stream.writeInt(inputObject.mask);
out_stream.write(inputObject.ipaddr.getBytes(), 0, inputObject.ipaddr.getBytes().length > 20 ? 20 : inputObject.ipaddr.getBytes().length);
if (inputObject.ipaddr.getBytes().length < 20) {
byte[] temp = new byte[20 - inputObject.ipaddr.getBytes().length];
out_stream.write(temp, 0, temp.length);
}
out_stream.write(inputObject.subnet.getBytes(), 0, inputObject.subnet.getBytes().length > 20 ? 20 : inputObject.subnet.getBytes().length);
if (inputObject.subnet.getBytes().length < 20) {
byte[] temp = new byte[20 - inputObject.subnet.getBytes().length];
out_stream.write(temp, 0, temp.length);
}
out_stream.write(inputObject.gateway.getBytes(), 0, inputObject.gateway.getBytes().length > 20 ? 20 : inputObject.gateway.getBytes().length);
if (inputObject.gateway.getBytes().length < 20) {
byte[] temp = new byte[20 - inputObject.gateway.getBytes().length];
out_stream.write(temp, 0, temp.length);
}
logger.fine("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"); // DEGUG
logger.fine("[SetRouteMcu/execute] GUI->NEMANAGER"); // DEGUG
logger.fine("[Execute/GUI->NEMANAGER]nodeId = " + inputObject.nodeId); // DEGUG
logger.fine("[Execute/GUI->NEMANAGER]shelfId = " + inputObject.shelfId); // DEGUG
logger.fine("[Execute/GUI->NEMANAGER]slotId = " + inputObject.slotId); // DEGUG
logger.fine("[Execute/GUI->NEMANAGER]portId = " + inputObject.portId); // DEGUG
logger.fine("[Execute/GUI->NEMANAGER]sysType = " + inputObject.sysType); // DEGUG
logger.fine("[Execute/GUI->NEMANAGER]oprtype = " + inputObject.oprtype); // DEGUG
logger.fine("[Execute/GUI->NEMANAGER]mask = " + inputObject.mask); // DEGUG
logger.fine("[Execute/GUI->NEMANAGER]ipaddr = " + inputObject.ipaddr); // DEGUG
logger.fine("[Execute/GUI->NEMANAGER]subnet = " + inputObject.subnet); // DEGUG
logger.fine("[Execute/GUI->NEMANAGER]gateway = " + inputObject.gateway); // DEGUG
logger.fine("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"); // DEGUG
out_stream.writeInt(0);
out_stream.writeInt(0);
out_stream.flush();
out_stream.close();
byte[] sendBuffer = baos.toByteArray();
DataInputStream in_stream = null;
DatagramPacket packet = new DatagramPacket(sendBuffer, sendBuffer.length, InetAddress.getByName(neIpAddr), NeConstants.AGENT_PORT);
socket = new DatagramSocket();
socket.setSoTimeout(NeConstants.TIME_OUT);
socket.send(packet);
packet = new DatagramPacket(receiveBuffer, receiveBuffer.length);
while (true) {
socket.receive(packet);
in_stream = new DataInputStream(new ByteArrayInputStream(receiveBuffer));
// header processing
headerInfo = new MpHeaderInfo(in_stream);
// invokeId
if (headerInfo.getInvokeId() != header.getInvokeId()) {
continue; // .. timeout??
}
/*
* ackBuffer = header.getAckHeaderByte(1, //version cmdTag, // invokeId NeConstants.NO_MORE, //moreFlag 0, //seqNo NeConstants.CMD_ACK, //cmdType 0, //msgType NeConstants.NEIF, //channel shelfId, //sid neIpAddr, // aganetIp 0, // result 0, //length cmdCode //commandId ); packet = new DatagramPacket(ackBuffer, ackBuffer.length, InetAddress.getByName(neIpAddr), NeConstants.AGENT_PORT); socket.send(packet);
*/
if (headerInfo.getResult() != NeConstants.SUCCESS) {
in_stream.close();
socket.close();
cmdDispatcher.cmdResponse(cmdTag, viewId, userId, nodeId, shelfId, cmdCode, data, headerInfo.getResult());
return;
} else {
in_stream.close();
socket.close();
cmdDispatcher.cmdResponse(cmdTag, viewId, userId, nodeId, shelfId, cmdCode, data, ErrorInspect.SUCCESS);
return;
}
}
} catch (SocketTimeoutException ste) {
logger.fine("[SetRouteMcu/execute] SocketTimeoutException <- " + cmdCode + " !!!"); // DEGUG
cmdDispatcher.cmdResponse(cmdTag, viewId, userId, nodeId, shelfId, cmdCode, data, ErrorInspect.SERVER_TIMEOUT_ERR);
return;
} catch (UnknownHostException uhe) {
logger.fine("[SetRouteMcu/execute] UnknownHostException <- " + cmdCode + " !!!"); // DEGUG
cmdDispatcher.cmdResponse(cmdTag, viewId, userId, nodeId, shelfId, cmdCode, data, ErrorInspect.HOST_UNKNOWN);
return;
} catch (Exception e) {
logger.fine("[SetRouteMcu/execute] Exception <- " + cmdCode + " !!!"); // DEGUG
e.printStackTrace(); // DEGUG
cmdDispatcher.cmdResponse(cmdTag, viewId, userId, nodeId, shelfId, cmdCode, data, ErrorInspect.FAILURE);
return;
} finally {
if (socket != null)
socket.close();
}
}
}
|