Skip to Content.
Sympa Menu

perfsonar-dev - r2054 - trunk/perfsonar/src/org/perfsonar/service/measurementPoint/flowType

Subject: perfsonar development work

List archive

r2054 - trunk/perfsonar/src/org/perfsonar/service/measurementPoint/flowType


Chronological Thread 
  • From:
  • To:
  • Subject: r2054 - trunk/perfsonar/src/org/perfsonar/service/measurementPoint/flowType
  • Date: Mon, 12 Feb 2007 07:50:07 -0500

Author: joost
Date: 2007-02-12 07:50:06 -0500 (Mon, 12 Feb 2007)
New Revision: 2054

Modified:

trunk/perfsonar/src/org/perfsonar/service/measurementPoint/flowType/ConfigFileWriter.java

trunk/perfsonar/src/org/perfsonar/service/measurementPoint/flowType/FlowTypeConstants.java

trunk/perfsonar/src/org/perfsonar/service/measurementPoint/flowType/FlowTypeMPServiceEngine.java

trunk/perfsonar/src/org/perfsonar/service/measurementPoint/flowType/ZebedeeControl.java
Log:
Fixed some issues (max number of clients)
Some new functionalities (delete config files on startup/shutdown)

Modified:
trunk/perfsonar/src/org/perfsonar/service/measurementPoint/flowType/ConfigFileWriter.java
===================================================================
---
trunk/perfsonar/src/org/perfsonar/service/measurementPoint/flowType/ConfigFileWriter.java
2007-02-12 12:44:19 UTC (rev 2053)
+++
trunk/perfsonar/src/org/perfsonar/service/measurementPoint/flowType/ConfigFileWriter.java
2007-02-12 12:50:06 UTC (rev 2054)
@@ -16,71 +16,124 @@
* Writes a config file for the flowmp python scripts (nfdump) to read.
*
* @author Joost de Mes
- *
+ *
*/
public class ConfigFileWriter {

- /**
- * Creates a config file for the nfdump proces
- *
- * @param key The unique key of this tunnel (will be the filename).
- * @param params Parameters derived from the soap request.
- * @param routers A list of routers derived from the soap request.
- * @throws SystemException When the configuration or logger component
fails.
- * @throws IOException When the configuration file cannot be written.
- */
- public static void save(Integer key, Hashtable<String,String> params,
ArrayList<String> routers) throws SystemException, IOException {
-
- LoggerComponent logger = (LoggerComponent)
- AuxiliaryComponentManager.getInstance().
- getComponent(ComponentNames.LOGGER);
+ /**
+ * Creates a config file for the nfdump proces
+ *
+ * @param key
+ * The unique key of this tunnel (will be the filename).
+ * @param params
+ * Parameters derived from the soap request.
+ * @param routers
+ * A list of routers derived from the soap request.
+ * @throws SystemException
+ * When the configuration or logger component fails.
+ * @throws IOException
+ * When the configuration file cannot be written.
+ */
+ public static void save(Integer key, Hashtable<String, String> params,
+ ArrayList<String> routers) throws SystemException,
IOException {

- ConfigurationComponent configuration = (ConfigurationComponent)
- AuxiliaryComponentManager.getInstance().
- getComponent(ComponentNames.CONFIG);
-
- String configBasePath =
configuration.getProperty("service.mp.flow.client_dir");
-
- File configFile = new File(configBasePath + "/" + key + ".xml");
-
- logger.debug("FlowTypeMpServiceEngine -> ConfigFileWriter: Writing
config file " + configFile.getAbsolutePath());
-
- FileWriter out = new FileWriter(configFile);
-
- out.write("<flow-client>\n");
- for(String name: params.keySet()) {
- out.write("\t<" + name + ">" + params.get(name) + "</" + name +
">\n");
+ LoggerComponent logger = (LoggerComponent)
AuxiliaryComponentManager
+
.getInstance().getComponent(ComponentNames.LOGGER);
+
+ ConfigurationComponent configuration =
(ConfigurationComponent) AuxiliaryComponentManager
+
.getInstance().getComponent(ComponentNames.CONFIG);
+
+ String configBasePath = configuration
+ .getProperty("service.mp.flow.client_dir");
+
+ File configFile = new File(configBasePath + "/" + key +
".xml");
+
+ logger
+ .debug("FlowTypeMpServiceEngine ->
ConfigFileWriter: Writing config file "
+ +
configFile.getAbsolutePath());
+
+ FileWriter out = new FileWriter(configFile);
+
+ out.write("<flow-client>\n");
+ for (String name : params.keySet()) {
+ out.write("\t<" + name + ">" +
encodeEntities(params.get(name)) + "</" + name
+ + ">\n");
+ }
+ out.write("\t<routers>\n");
+ for (String router : routers) {
+ out.write("\t\t<router>" + encodeEntities(router) +
"</router>\n");
+ }
+ out.write("\t</routers>\n");
+ out.write("</flow-client>\n");
+
+ out.close();
}
- out.write("\t<routers>\n");
- for(String router: routers) {
- out.write("\t\t<router>" + router + "</router>\n");
+
+ /**
+ * Encodes < & > ' " characters to their entities.
+ *
+ * @param value the value to be encoded.
+ * @return
+ */
+ private static String encodeEntities(String value) {
+ value = value.replaceAll("\\&", "&amp;");
+ value = value.replaceAll("\\<", "&lt;");
+ value = value.replaceAll("\\>", "&gt;");
+ value = value.replaceAll("\\'", "&apos;");
+ value = value.replaceAll("\\\"", "&quot;");
+ return value;
}
- out.write("\t</routers>\n");
- out.write("</flow-client>\n");

- out.close();
- }
-
- /**
- * Deletes the written config file for the nfdump proces
- * @param key The unique key of this tunnel (will be the filename).
- * @throws SystemException
- */
- public static void delete(Integer key) throws SystemException {
- LoggerComponent logger = (LoggerComponent)
- AuxiliaryComponentManager.getInstance().
- getComponent(ComponentNames.LOGGER);
+ /**
+ * Deletes the written config file for the nfdump proces
+ *
+ * @param key
+ * The unique key of this tunnel (will be the filename).
+ * @throws SystemException
+ */
+ public static void delete(Integer key) throws SystemException {
+ LoggerComponent logger = (LoggerComponent)
AuxiliaryComponentManager
+
.getInstance().getComponent(ComponentNames.LOGGER);

- ConfigurationComponent configuration = (ConfigurationComponent)
- AuxiliaryComponentManager.getInstance().
- getComponent(ComponentNames.CONFIG);
-
- String configBasePath =
configuration.getProperty("service.mp.flow.client_dir");
-
- File configFile = new File(configBasePath + "/" + key + ".xml");
-
- if(configFile.exists()) {
- configFile.delete();
- }
- }
+ ConfigurationComponent configuration =
(ConfigurationComponent) AuxiliaryComponentManager
+
.getInstance().getComponent(ComponentNames.CONFIG);
+
+ String configBasePath = configuration
+ .getProperty("service.mp.flow.client_dir");
+
+ File configFile = new File(configBasePath + "/" + key +
".xml");
+
+ if (configFile.exists()) {
+ configFile.delete();
+ logger.debug("FlowTypeMpServiceEngine ->
ConfigFileWriter: deleted configFile with key " + key);
+ }
+ }
+
+ /**
+ * Cleans the configuration files on services startup.
+ *
+ * @throws SystemException
+ * when logger or configuration component fails
+ */
+ public static void cleanUp() throws SystemException {
+
+ LoggerComponent logger = (LoggerComponent)
AuxiliaryComponentManager
+
.getInstance().getComponent(ComponentNames.LOGGER);
+
+ ConfigurationComponent configuration =
(ConfigurationComponent) AuxiliaryComponentManager
+
.getInstance().getComponent(ComponentNames.CONFIG);
+
+ String configBasePath = configuration
+ .getProperty("service.mp.flow.client_dir");
+ Integer maxConn = Integer.parseInt(configuration
+ .getProperty("service.mp.flow.max_conn"));
+ for (Integer key = 1; key < maxConn; key++) {
+ File configFile = new File(configBasePath + "/" + key
+ ".xml");
+
+ if (configFile.exists()) {
+ configFile.delete();
+ logger.debug("FlowTypeMpServiceEngine ->
ConfigFileWriter: deleted configFile with key " + key);
+ }
+ }
+ }
}

Modified:
trunk/perfsonar/src/org/perfsonar/service/measurementPoint/flowType/FlowTypeConstants.java
===================================================================
---
trunk/perfsonar/src/org/perfsonar/service/measurementPoint/flowType/FlowTypeConstants.java
2007-02-12 12:44:19 UTC (rev 2053)
+++
trunk/perfsonar/src/org/perfsonar/service/measurementPoint/flowType/FlowTypeConstants.java
2007-02-12 12:50:06 UTC (rev 2054)
@@ -5,46 +5,45 @@
*/
package org.perfsonar.service.measurementPoint.flowType;

-
/**
* @author loukik
- *
- * TODO To change the template for this generated type comment go to
- * Window - Preferences - Java - Code Style - Code Templates
+ *
+ * TODO To change the template for this generated type comment go to Window -
+ * Preferences - Java - Code Style - Code Templates
*/
public class FlowTypeConstants {
-
- public static final String KEY_CLIENT_ADDRESS = "clientaddress";

- public static final String KEY_CLIENT_PORT = "clientport";
+ public static final String KEY_CLIENT_ADDRESS = "clientaddress";

- public static final String KEY_SUBSCRIPTION = "maSubscription";
+ public static final String KEY_CLIENT_PORT = "clientport";

- //Request types
- public static String FLOW_SUBSCRIBE="SubscriptionRequest";
+ public static final String KEY_SUBSCRIPTION = "maSubscription";

- public static String FLOW_KEEPALIVE="SubscriptionKeepaliveRequest";
-
- public static String FLOW_UNSUBSCRIBE="UnSubscriptionRequest";
-
- //response types
- public static String FLOW_SUBSCRIBE_RESPONSE ="SubscriptionResponse";
+ // Request types
+ public static String FLOW_SUBSCRIBE = "SubscriptionRequest";

- public static String FLOW_KEEPALIVE_RESPONSE
="SubscriptionKeepaliveResponse";
-
- public static String FLOW_UNSUBSCRIBE_RESPONSE ="UnSubscriptionResponse";
-
- public static String[] getListedRequestTypes() {
-
- String[] requestTypeList = new String[3];
-
- requestTypeList[0]=FLOW_SUBSCRIBE;
-
- requestTypeList[1]=FLOW_KEEPALIVE;
-
- requestTypeList[2]=FLOW_UNSUBSCRIBE;
-
- return requestTypeList;
-
- }
+ public static String FLOW_KEEPALIVE = "SubscriptionKeepaliveRequest";
+
+ public static String FLOW_UNSUBSCRIBE = "UnSubscriptionRequest";
+
+ // response types
+ public static String FLOW_SUBSCRIBE_RESPONSE = "SubscriptionResponse";
+
+ public static String FLOW_KEEPALIVE_RESPONSE =
"SubscriptionKeepaliveResponse";
+
+ public static String FLOW_UNSUBSCRIBE_RESPONSE =
"UnSubscriptionResponse";
+
+ public static String[] getListedRequestTypes() {
+
+ String[] requestTypeList = new String[3];
+
+ requestTypeList[0] = FLOW_SUBSCRIBE;
+
+ requestTypeList[1] = FLOW_KEEPALIVE;
+
+ requestTypeList[2] = FLOW_UNSUBSCRIBE;
+
+ return requestTypeList;
+
+ }
}

Modified:
trunk/perfsonar/src/org/perfsonar/service/measurementPoint/flowType/FlowTypeMPServiceEngine.java
===================================================================
---
trunk/perfsonar/src/org/perfsonar/service/measurementPoint/flowType/FlowTypeMPServiceEngine.java
2007-02-12 12:44:19 UTC (rev 2053)
+++
trunk/perfsonar/src/org/perfsonar/service/measurementPoint/flowType/FlowTypeMPServiceEngine.java
2007-02-12 12:50:06 UTC (rev 2054)
@@ -11,13 +11,11 @@

import org.ggf.ns.nmwg.base.v2_0.Data;
import org.ggf.ns.nmwg.base.v2_0.Datum;
-import org.ggf.ns.nmwg.base.v2_0.Element;
import org.ggf.ns.nmwg.base.v2_0.EventType;
import org.ggf.ns.nmwg.base.v2_0.Key;
import org.ggf.ns.nmwg.base.v2_0.Message;
import org.ggf.ns.nmwg.base.v2_0.Metadata;
import org.ggf.ns.nmwg.base.v2_0.Parameter;
-import org.ggf.ns.nmwg.base.v2_0.Parameters;
import org.ggf.ns.nmwg.tools.netflow.v2_0.Subject;
import org.perfsonar.commons.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.commons.auxiliary.ComponentNames;
@@ -30,340 +28,403 @@
import org.perfsonar.service.commons.exceptions.SystemException;

/**
- * Service Engine implementation for flow MP.
+ * Service Engine implementation for flow MP.
*
* @author Joost de Mes
- *
+ *
*/
public class FlowTypeMPServiceEngine implements ServiceEngine {
- // ----------------------------Member Variables
- /**
- * The type of this ServiceEngine.
- */
- public String serviceEngineType;
-
- /**
- * Logger component.
- */
- private LoggerComponent logger = null;
+ // ----------------------------Member Variables
+ /**
+ * The type of this ServiceEngine.
+ */
+ public String serviceEngineType;

- /**
- * Configuration component.
- */
- private ConfigurationComponent configuration = null;
-
- // -----------------------------Constructor
- /**
- * Instantiates the FlowTypeMPServiceEngine.
- */
- public FlowTypeMPServiceEngine() throws SystemException {
-
- this.serviceEngineType = "FlowTypeMPServiceEngine";
-
- this.logger = (LoggerComponent)AuxiliaryComponentManager.
- getInstance().getComponent(ComponentNames.LOGGER);
+ /**
+ * Logger component.
+ */
+ private LoggerComponent logger = null;

- this.configuration = (ConfigurationComponent)
- AuxiliaryComponentManager.getInstance().
- getComponent(ComponentNames.CONFIG);
+ /**
+ * Configuration component.
+ */
+ private ConfigurationComponent configuration = null;

- }
-
- // ---------------------------- Public Methods
- /**
- * Returns a string containing the type of the ServiceEngine.
- *
- * @return The type of ServiceEngine.
- */
- public String getType() {
- return this.serviceEngineType;
- }
+ // -----------------------------Constructor
+ /**
+ * Instantiates the FlowTypeMPServiceEngine.
+ */
+ public FlowTypeMPServiceEngine() throws SystemException {

-
- /**
- * Implemented method which takes in the request along with an action
type
- * and gives back a response based on the capabilities of the service.
- *
- * FlowTypeMPServiceEngine only has 3 possible requestTypes:
- * - subscribe to open a tunnel
- * - keepalive to keep a tunnel open
- * - unsubscribe to close a tunnel
- *
- * @param actionType String object which specifies the action type to be
taken
- * @param request object of type Message containing the request
- *
- * @return A response with a unique key identifying the tunnel.
- */
- public Message takeAction(String actionType, Message request)
- throws SystemException, ResourceException,
- DataFormatException, RequestException {
-
- logger.debug("FlowTypeMPServiceEngine: request.getType() = " +
request.getType());
-
- if(request.getType().equals(FlowTypeConstants.FLOW_KEEPALIVE)) {
- return keepalive(request);
- } else if(request.getType().equals(FlowTypeConstants.FLOW_SUBSCRIBE))
{
- return subscribe(request);
- } else
if(request.getType().equals(FlowTypeConstants.FLOW_UNSUBSCRIBE)) {
- return unsubscribe(request);
- } else {
- throw new RequestException("Request type " + request.getType() +
" not understood.");
- }
- }
+ this.serviceEngineType = "FlowTypeMPServiceEngine";

- // ---------------------------- Private Methods
-
- // ---------------------------- Methods for filtering data from requests
- /**
- * Takes the subscription request, and filters out the common parameters.
- *
- * @param request The incomming request (should be subscription request).
- *
- * @return a hashtable with key,value pairs of common parameters.
- * @throws DataFormatException When parameters aren't properly formatted.
- */
- private Hashtable<String,String> filterCommonParams(Message request)
throws DataFormatException {
- //TODO validate parameter list
- Hashtable<String,String> params = new Hashtable<String,String>();
-
- //Meta data items (routers and common options)
- for(Metadata meta: request.getMetadataArray()) {
- //the first MD block contains information common to the router
selection information
- if(meta.getParameters() != null &&
- meta.getParameters() instanceof
org.ggf.ns.nmwg.tools.netflow.v2_0.Parameters) {
- logger.debug("Common router selection information:");
- for(Parameter param:
((org.ggf.ns.nmwg.tools.netflow.v2_0.Parameters)meta.getParameters()).
- getParameterArray()) {
- logger.debug("" + param.getParameterName() + " = " +
param.getParameterValue());
- params.put(param.getParameterName(),
param.getParameterValue());
- }
- }
- }
- return params;
- }
-
- /**
- * Takes the subcription request, and filters out the list of
routernames.
- *
- * @param request The incomming request (should be subscription
request).
- * @return an ArrayList with routernames (Strings).
- * @throws DataFormatException When there are no routers in the list, or
the routernames aren't properly formatted.
- */
- private ArrayList<String> filterRouters(Message request) throws
DataFormatException {
- //TODO validate routerlist
- ArrayList<String> routers = new ArrayList<String>();
+ this.logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
+ .getComponent(ComponentNames.LOGGER);
+
+ this.configuration = (ConfigurationComponent)
AuxiliaryComponentManager
+
.getInstance().getComponent(ComponentNames.CONFIG);
+
+ // Clean up the configuration directory on service startup
+ ConfigFileWriter.cleanUp();
+ }

- //Meta data items (routers and common options)
- for(Metadata meta: request.getMetadataArray()) {
- if(meta.getSubject() != null &&
- meta.getSubject() instanceof
org.ggf.ns.nmwg.tools.netflow.v2_0.Subject) {
- Subject subj =
(org.ggf.ns.nmwg.tools.netflow.v2_0.Subject)meta.getSubject();
- logger.debug("" + subj.getRouter().getName().getName());
-
- //add the routers to the list by name
- routers.add(subj.getRouter().getName().getName());
- }
- }
- if(routers.size() < 1) {
- throw new DataFormatException("No routers found in request.");
- } else {
- //TODO check routernames with configured list
- return routers;
- }
- }
-
- /**
- * Takes the subscription request, and filters out the (client) endpoint
address and portnumber.
- *
- * @param request The incomming request (should be subscription
request).
- * @return a Hashtable with key,value pairs containing the client
address and the client portnumber.
- * @throws DataFormatException When the client endpoint parameters
aren't properly formatted.
- */
- private Hashtable<String,String> filterEndPointParams(Message request)
throws DataFormatException {
- Hashtable<String,String> clientParams = new
Hashtable<String,String>();
-
- //Data item, client options
- for(Data dat: request.getDataArray()) {
- //Search in data items
- for(Metadata meta: dat.getMetadataArray()) {
- //with a metadata item
- if(meta.getSubject() != null && meta.getSubject() instanceof
org.ggf.ns.nmwg.tools.netflow.v2_0.Subject) {
- //that is of type
org.ggf.ns.nmwg.tools.netflow.v2_0.Subject
- Subject subj =
((org.ggf.ns.nmwg.tools.netflow.v2_0.Subject)meta.getSubject());
- if(subj.getEndPoint() != null) {
- //and has an endpoint element
-
- String address =
subj.getEndPoint().getAddressElement().getAddress();
- if(address != null) {
-
clientParams.put(FlowTypeConstants.KEY_CLIENT_ADDRESS, address);
- } else {
- throw new DataFormatException("endpoint address
is not set.");
+ public void finalize() throws Throwable {
+ // Clean up the configuration directory on service shutdown
+ ConfigFileWriter.cleanUp();
+ }
+
+ // ---------------------------- Public Methods
+ /**
+ * Returns a string containing the type of the ServiceEngine.
+ *
+ * @return The type of ServiceEngine.
+ */
+ public String getType() {
+ return this.serviceEngineType;
+ }
+
+ /**
+ * Implemented method which takes in the request along with an action
type
+ * and gives back a response based on the capabilities of the service.
+ *
+ * FlowTypeMPServiceEngine only has 3 possible requestTypes: -
subscribe to
+ * open a tunnel - keepalive to keep a tunnel open - unsubscribe to
close a
+ * tunnel
+ *
+ * @param actionType
+ * String object which specifies the action type to be
taken
+ * @param request
+ * object of type Message containing the request
+ *
+ * @return A response with a unique key identifying the tunnel.
+ */
+ public Message takeAction(String actionType, Message request)
+ throws SystemException, ResourceException,
DataFormatException,
+ RequestException {
+
+ logger.debug("FlowTypeMPServiceEngine: request.getType() = "
+ + request.getType());
+
+ if
(request.getType().equals(FlowTypeConstants.FLOW_KEEPALIVE)) {
+ return keepalive(request);
+ } else if
(request.getType().equals(FlowTypeConstants.FLOW_SUBSCRIBE)) {
+ return subscribe(request);
+ } else if
(request.getType().equals(FlowTypeConstants.FLOW_UNSUBSCRIBE)) {
+ return unsubscribe(request);
+ } else {
+ throw new
SystemException("error.common.action_not_supported","Request type " +
request.getType()
+ + " not understood.");
+ }
+ }
+
+ // ---------------------------- Private Methods
+
+ // ---------------------------- Methods for filtering data from
requests
+ /**
+ * Takes the subscription request, and filters out the common
parameters.
+ *
+ * @param request
+ * The incomming request (should be subscription request).
+ *
+ * @return a hashtable with key,value pairs of common parameters.
+ * @throws DataFormatException
+ * When parameters aren't properly formatted.
+ */
+ private Hashtable<String, String> filterCommonParams(Message request)
+ throws DataFormatException {
+ // TODO validate parameter list
+ Hashtable<String, String> params = new Hashtable<String,
String>();
+
+ // Meta data items (routers and common options)
+ for (Metadata meta : request.getMetadataArray()) {
+ // the first MD block contains information common to
the router
+ // selection information
+ if (meta.getParameters() != null
+ && meta.getParameters() instanceof
org.ggf.ns.nmwg.tools.netflow.v2_0.Parameters) {
+ logger.debug("Common router selection
information:");
+ for (Parameter param :
((org.ggf.ns.nmwg.tools.netflow.v2_0.Parameters) meta
+
.getParameters()).getParameterArray()) {
+ logger.debug("" +
param.getParameterName() + " = "
+ +
param.getParameterValue());
+ params.put(param.getParameterName(),
param
+ .getParameterValue());
+ }
}
+ }
+ return params;
+ }

- String port = subj.getEndPoint().getPort();
- if(port != null) {
-
clientParams.put(FlowTypeConstants.KEY_CLIENT_PORT, port);
- } else {
- throw new DataFormatException("endpoint port is
not set.");
+ /**
+ * Takes the subcription request, and filters out the list of
routernames.
+ *
+ * @param request
+ * The incomming request (should be subscription request).
+ * @return an ArrayList with routernames (Strings).
+ * @throws DataFormatException
+ * When there are no routers in the list, or the
routernames
+ * aren't properly formatted.
+ */
+ private ArrayList<String> filterRouters(Message request)
+ throws DataFormatException {
+ // TODO validate routerlist
+ ArrayList<String> routers = new ArrayList<String>();
+
+ // Meta data items (routers and common options)
+ for (Metadata meta : request.getMetadataArray()) {
+ if (meta.getSubject() != null
+ && meta.getSubject() instanceof
org.ggf.ns.nmwg.tools.netflow.v2_0.Subject) {
+ Subject subj =
(org.ggf.ns.nmwg.tools.netflow.v2_0.Subject) meta
+ .getSubject();
+ logger.debug("" +
subj.getRouter().getName().getName());
+
+ // add the routers to the list by name
+
routers.add(subj.getRouter().getName().getName());
}
-
- return clientParams;
- }
}
- }
+ if (routers.size() < 1) {
+ throw new DataFormatException("No routers found in
request.");
+ } else {
+ // TODO check routernames with configured list
+ return routers;
+ }
}
- throw new DataFormatException("No endpoint found in request.");
- }
-
- /**
- * Takes a unsubscription/keepalive request.
- *
- * @param request A unsubscription/keepalive request containing the key.
- * @return the unique key from the request.
- * @throws DataFormatException if the key is not properly formatted, or
does not exist.
- */
- private Integer filterKey(Message request) throws DataFormatException {
- //search for a metadata element
- for(Metadata meta: request.getMetadataArray()) {
- //with a key element
- if(meta.getKey() != null) {
- //that has a
- if(meta.getKey().getParameterByName("maSubscription") !=
null) {
- Parameter param =
meta.getKey().getParameterByName(FlowTypeConstants.KEY_SUBSCRIPTION);
- if(param != null && param.getParameterValue() != null) {
- Integer key =
Integer.parseInt(param.getParameterValue());
- if(key != null && key > 0) {
- return key;
- } else {
- throw new DataFormatException("Key is not
positive numeric.");
+
+ /**
+ * Takes the subscription request, and filters out the (client)
endpoint
+ * address and portnumber.
+ *
+ * @param request
+ * The incomming request (should be subscription request).
+ * @return a Hashtable with key,value pairs containing the client
address
+ * and the client portnumber.
+ * @throws DataFormatException
+ * When the client endpoint parameters aren't properly
+ * formatted.
+ */
+ private Hashtable<String, String> filterEndPointParams(Message
request)
+ throws DataFormatException {
+ Hashtable<String, String> clientParams = new
Hashtable<String, String>();
+
+ // Data item, client options
+ for (Data dat : request.getDataArray()) {
+ // Search in data items
+ for (Metadata meta : dat.getMetadataArray()) {
+ // with a metadata item
+ if (meta.getSubject() != null
+ && meta.getSubject()
instanceof org.ggf.ns.nmwg.tools.netflow.v2_0.Subject) {
+ // that is of type
+ //
org.ggf.ns.nmwg.tools.netflow.v2_0.Subject
+ Subject subj =
((org.ggf.ns.nmwg.tools.netflow.v2_0.Subject) meta
+ .getSubject());
+ if (subj.getEndPoint() != null) {
+ // and has an endpoint element
+
+ String address =
subj.getEndPoint().getAddressElement()
+ .getAddress();
+ if (address != null) {
+ clientParams.put(
+
FlowTypeConstants.KEY_CLIENT_ADDRESS,
+
address);
+ } else {
+ throw new
DataFormatException(
+
"endpoint address is not set.");
+ }
+
+ String port =
subj.getEndPoint().getPort();
+ if (port != null) {
+
clientParams.put(FlowTypeConstants.KEY_CLIENT_PORT,
+ port);
+ } else {
+ throw new
DataFormatException(
+
"endpoint port is not set.");
+ }
+
+ return clientParams;
+ }
+ }
}
- }
}
- }
+ throw new DataFormatException("No endpoint found in
request.");
}
- throw new DataFormatException("No key found in request.");
- }

- // ---------------------------- Helper methods for this service
- /**
- * Helper method to subscribe a client to a tunnel.
- *
- * @param request a subscription request.
- *
- * @return a Message object that should be returned to the client.
- */
- private Message subscribe(Message request) throws DataFormatException,
SystemException {
- ArrayList<String> routers = new ArrayList<String>();
- Hashtable<String,String> params = new Hashtable<String,String>();
-
- //get the common parameters
- params.putAll(filterCommonParams(request));
-
- //get the client endpoint params
- params.putAll(filterEndPointParams(request));
-
- //get the list of routernames
- routers = filterRouters(request);
-
-
- logger.debug("common params: " + params);
- logger.debug("routers: " + routers);
-
- //start new tunnel
- try {
- Integer portNr =
Integer.parseInt(params.get(FlowTypeConstants.KEY_CLIENT_PORT));
- if(portNr == null || portNr < 0 || portNr > 65535) {
- throw new DataFormatException("Invalid portnumber");
- }
- Integer key = ZebedeeControl.getInstance().startTunnel
- (params.get(FlowTypeConstants.KEY_CLIENT_ADDRESS),portNr);
-
- ConfigFileWriter.save(key,params,routers);
-
- return createResponse(FlowTypeConstants.FLOW_SUBSCRIBE_RESPONSE,
- key,"Tunnel opened with key [" + key + "]");
- } catch (IOException e) {
- //TODO Auto-generated catch block
- e.printStackTrace();
- throw new SystemException("IOException was thrown when opening
tunnel",e);
- }
- }
-
- /**
- * Helper method to unsubscribe a client from a tunnel.
- *
- * @param request a unsubscription request.
- *
- * @return a Message object that should be returned to the client.
- */
- private Message unsubscribe(Message request) throws SystemException,
DataFormatException {
- //stop tunnel
- Integer key = filterKey(request);
-
- ZebedeeControl.getInstance().stopTunnel(key);
- return createResponse(FlowTypeConstants.FLOW_UNSUBSCRIBE_RESPONSE,
- key,"Tunnel with key [" + key + "] was closed");
- }
-
- /**
- * Helper method to send a keep alive for a tunnel.
- *
- * @param request a keepalive request.
- *
- * @return a Message object that should be returned to the client.
- */
- private Message keepalive(Message request) throws SystemException,
DataFormatException {
- //Keep alive
- Integer key = filterKey(request);
- ZebedeeControl.getInstance().keepAlive(key);
- return createResponse(FlowTypeConstants.FLOW_KEEPALIVE_RESPONSE,
- key,"Tunnel received keepalive with key [" + key + "]");
- }
-
- // ---------------------------- Response generators
-
- /**
- * Creates a response Message. For this ServiceEngine all responses look
alike, with a key, a responsetype and a message.
- *
- * @param responseType The response type.
- * @param key The unique tunnel key.
- * @param a message to explain the response.
- *
- * @return a ready-to-send response Message.
- */
- private Message createResponse(String responseType, Integer key, String
message) {
- Message response = new Message();
-
- response.setType(responseType);
-
- Metadata meta = new Metadata();
- meta.setId("resultCodeMetadata");
-
- EventType evt = new EventType();
- evt.setEventType("result.success");
- meta.addChild(evt);
-
- Parameter param = new Parameter();
- param.setParameterName(FlowTypeConstants.KEY_SUBSCRIPTION);
- param.setParameterValue("" + key);
-
- Key keyElement = new Key();
- keyElement.addParameter(param);
-
- meta.addChild(keyElement);
-
- Data data = new Data();
- data.setId("resultCodeData");
- data.setMetadataIdRef(meta.getId());
-
- Datum msgDatum = new Datum();
- msgDatum.setDatum(message);
- data.addChild(msgDatum);
-
- response.setMetadata(meta);
- response.setData(data);
-
- //response.setCompleted(); ???
- return response;
- }
+ /**
+ * Takes a unsubscription/keepalive request.
+ *
+ * @param request
+ * A unsubscription/keepalive request containing the key.
+ * @return the unique key from the request.
+ * @throws DataFormatException
+ * if the key is not properly formatted, or does not
exist.
+ */
+ private Integer filterKey(Message request) throws DataFormatException
{
+ // search for a metadata element
+ for (Metadata meta : request.getMetadataArray()) {
+ // with a key element
+ if (meta.getKey() != null) {
+ // that has a
+ if
(meta.getKey().getParameterByName("maSubscription") != null) {
+ Parameter param =
meta.getKey().getParameterByName(
+
FlowTypeConstants.KEY_SUBSCRIPTION);
+ if (param != null &&
param.getParameterValue() != null) {
+ Integer key =
Integer.parseInt(param
+
.getParameterValue());
+ if (key != null && key > 0) {
+ return key;
+ } else {
+ throw new
DataFormatException(
+ "Key
is not positive numeric.");
+ }
+ }
+ }
+ }
+ }
+ throw new DataFormatException("No key found in request.");
+ }
+
+ // ---------------------------- Helper methods for this service
+ /**
+ * Helper method to subscribe a client to a tunnel.
+ *
+ * @param request
+ * a subscription request.
+ *
+ * @return a Message object that should be returned to the client.
+ */
+ private Message subscribe(Message request) throws DataFormatException,
+ SystemException {
+ ArrayList<String> routers = new ArrayList<String>();
+ Hashtable<String, String> params = new Hashtable<String,
String>();
+
+ // get the common parameters
+ params.putAll(filterCommonParams(request));
+
+ // get the client endpoint params
+ params.putAll(filterEndPointParams(request));
+
+ // generate a anonymizing key for use with zebedee
+ params.put("anonymizingkey", ZebedeeControl.getInstance()
+ .generateAnonymizingKey());
+
+ // get the list of routernames
+ routers = filterRouters(request);
+
+ logger.debug("common params: " + params);
+ logger.debug("routers: " + routers);
+
+ // start new tunnel
+ try {
+ Integer portNr = Integer.parseInt(params
+
.get(FlowTypeConstants.KEY_CLIENT_PORT));
+ if (portNr == null || portNr < 0 || portNr > 65535) {
+ throw new DataFormatException("Invalid
portnumber");
+ }
+ Integer key =
ZebedeeControl.getInstance().startTunnel(
+
params.get(FlowTypeConstants.KEY_CLIENT_ADDRESS), portNr);
+
+ //check for max clients reached
+ if(key == -1) {
+ throw new
SystemException("error.mp.flow.max_clients_reached","The maximum number of
clients is reached, try again later.");
+ }
+
+ ConfigFileWriter.save(key, params, routers);
+
+ return
createResponse(FlowTypeConstants.FLOW_SUBSCRIBE_RESPONSE,
+ key, "Tunnel opened with key [" + key
+ "]");
+ } catch (IOException e) {
+ logger.error("FlowTypeMPServiceEngine: IOException! "
+ + e.getMessage());
+ for (StackTraceElement ste : e.getStackTrace()) {
+ logger.error(ste.toString());
+ }
+ throw new SystemException(
+ "IOException was thrown when opening
tunnel", e);
+ }
+ }
+
+ /**
+ * Helper method to unsubscribe a client from a tunnel.
+ *
+ * @param request
+ * a unsubscription request.
+ *
+ * @return a Message object that should be returned to the client.
+ */
+ private Message unsubscribe(Message request) throws SystemException,
+ DataFormatException {
+ // stop tunnel
+ Integer key = filterKey(request);
+
+ ZebedeeControl.getInstance().stopTunnel(key);
+ return
createResponse(FlowTypeConstants.FLOW_UNSUBSCRIBE_RESPONSE, key,
+ "Tunnel with key [" + key + "] was closed");
+ }
+
+ /**
+ * Helper method to send a keep alive for a tunnel.
+ *
+ * @param request
+ * a keepalive request.
+ *
+ * @return a Message object that should be returned to the client.
+ */
+ private Message keepalive(Message request) throws SystemException,
+ DataFormatException {
+ // Keep alive
+ Integer key = filterKey(request);
+ ZebedeeControl.getInstance().keepAlive(key);
+ return
createResponse(FlowTypeConstants.FLOW_KEEPALIVE_RESPONSE, key,
+ "Tunnel received keepalive with key [" + key
+ "]");
+ }
+
+ // ---------------------------- Response generators
+
+ /**
+ * Creates a response Message. For this ServiceEngine all responses
look
+ * alike, with a key, a responsetype and a message.
+ *
+ * @param responseType
+ * The response type.
+ * @param key
+ * The unique tunnel key.
+ * @param a
+ * message to explain the response.
+ *
+ * @return a ready-to-send response Message.
+ */
+ private Message createResponse(String responseType, Integer key,
+ String message) {
+ Message response = new Message();
+
+ response.setType(responseType);
+
+ Metadata meta = new Metadata();
+ meta.setId("resultCodeMetadata");
+
+ EventType evt = new EventType();
+ evt.setEventType("result.success");
+ meta.addChild(evt);
+
+ Parameter param = new Parameter();
+ param.setParameterName(FlowTypeConstants.KEY_SUBSCRIPTION);
+ param.setParameterValue("" + key);
+
+ Key keyElement = new Key();
+ keyElement.addParameter(param);
+
+ meta.addChild(keyElement);
+
+ Data data = new Data();
+ data.setId("resultCodeData");
+ data.setMetadataIdRef(meta.getId());
+
+ Datum msgDatum = new Datum();
+ msgDatum.setDatum(message);
+ data.addChild(msgDatum);
+
+ response.setMetadata(meta);
+ response.setData(data);
+
+ // response.setCompleted(); ???
+ return response;
+ }
}
\ No newline at end of file

Modified:
trunk/perfsonar/src/org/perfsonar/service/measurementPoint/flowType/ZebedeeControl.java
===================================================================
---
trunk/perfsonar/src/org/perfsonar/service/measurementPoint/flowType/ZebedeeControl.java
2007-02-12 12:44:19 UTC (rev 2053)
+++
trunk/perfsonar/src/org/perfsonar/service/measurementPoint/flowType/ZebedeeControl.java
2007-02-12 12:50:06 UTC (rev 2054)
@@ -10,250 +10,311 @@
import
org.perfsonar.commons.auxiliary.components.configuration.ConfigurationComponent;
import org.perfsonar.commons.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.service.commons.exceptions.SystemException;
+
/**
* Controls a list of active zebedee tunnels, with keepalive feature.
*
* @author Joost de Mes (SURFnet)
- *
+ *
*/
-public class ZebedeeControl implements Runnable
-{
- /**
- * Singleton instance.
- */
- private static ZebedeeControl instance = null;
-
- /**
- * ArrayList with Keys.
- */
- private ArrayList<Integer> keyList = new ArrayList<Integer>();
-
- /**
- * HashMap with Key,Process items.
- */
- private HashMap<Integer,Process> processList = new
HashMap<Integer,Process>();
-
- /**
- * HashMap with key,updateTime items.
- */
- private HashMap<Integer,Long> keepAliveList = new
HashMap<Integer,Long>();
+public class ZebedeeControl implements Runnable {
+ /**
+ * Singleton instance.
+ */
+ private static ZebedeeControl instance = null;

- /**
- * Reference to the configuration component (to get stored configuration
parameters, such as routers and port numbers).
- */
- private ConfigurationComponent configuration;
+ /**
+ * ArrayList with Keys.
+ */
+ private ArrayList<Integer> keyList = new ArrayList<Integer>();

- /**
- * Reference to the logger component.
- */
- private LoggerComponent logger;
-
- /**
- * Full path to the zebedee executable. Read from configuration.
- */
- private String zebedeeExecutable;
-
- /**
- * Zebedee inportBase (inport = inportBase + key). Read from
configuration.
- */
- private Integer inPortBase;
+ /**
+ * HashMap with Key,Process items.
+ */
+ private HashMap<Integer, Process> processList = new HashMap<Integer,
Process>();

- /**
- * Zebedee betweenPortBase (betweenPort = betweenPortBase + key). Read
from configuration.
- */
- private Integer betweenPortBase;
-
- /**
- * The maximum time between two keepalive calls from the client
- */
- private static final long MAX_KEEPALIVE = 60000;
-
- /**
- * The time the thread sleeps between timeout checks
- */
- private static final long SLEEPTIME = 10000;
-
- /**
- * Singleton constructor.
- * @throws SystemException if configuration items can not be read.
- */
- private ZebedeeControl() throws SystemException {
- logger = (LoggerComponent)
- AuxiliaryComponentManager.getInstance().
- getComponent(ComponentNames.LOGGER);
-
- this.configuration = (ConfigurationComponent)
- AuxiliaryComponentManager.getInstance().
- getComponent(ComponentNames.CONFIG);
-
- zebedeeExecutable =
configuration.getProperty("service.mp.flow.zebedee");
- inPortBase =
Integer.parseInt(configuration.getProperty("service.mp.flow.inPort"));
- betweenPortBase =
Integer.parseInt(configuration.getProperty("service.mp.flow.betweenPort"));
- }
-
- /**
- * Singleton static access method. Creates an instance of this class if
there is none, and returns it. Returns a running thread.
- *
- * @return the singleton instance (a running ZebedeeControl thread
instance).
- * @throws SystemException if configuration items can not be read.
- */
- public static ZebedeeControl getInstance() throws SystemException {
- //If there's no instance, create it, and start it's thread.
- if(instance == null) {
- //create an instance (singleton).
- instance = new ZebedeeControl();
- //create a thread for this zebedee control instance.
- Thread zebedeeControlThread = new Thread(instance);
- //start the thread (calls the run method).
- zebedeeControlThread.start();
+ /**
+ * HashMap with key,updateTime items.
+ */
+ private HashMap<Integer, Long> keepAliveList = new HashMap<Integer,
Long>();
+
+ /**
+ * Reference to the configuration component (to get stored
configuration
+ * parameters, such as routers and port numbers).
+ */
+ private ConfigurationComponent configuration;
+
+ /**
+ * Reference to the logger component.
+ */
+ private LoggerComponent logger;
+
+ /**
+ * Full path to the zebedee executable. Read from configuration.
+ */
+ private String zebedeeExecutable;
+
+ /**
+ * Zebedee inportBase (inport = inportBase + key). Read from
configuration.
+ */
+ private Integer inPortBase;
+
+ /**
+ * Zebedee betweenPortBase (betweenPort = betweenPortBase + key).
Read from
+ * configuration.
+ */
+ private Integer betweenPortBase;
+
+ /**
+ * Maximum number of clients that can subscribe to this service
+ * simultaneously. Read from configuration.
+ */
+ private Integer maxConn;
+
+ /**
+ * The maximum time between two keepalive calls from the client
+ */
+ private static final long MAX_KEEPALIVE = 60000;
+
+ /**
+ * The time the thread sleeps between timeout checks
+ */
+ private static final long SLEEPTIME = 10000;
+
+ /**
+ * Singleton constructor.
+ *
+ * @throws SystemException
+ * if configuration items can not be read.
+ */
+ private ZebedeeControl() throws SystemException {
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
+ .getComponent(ComponentNames.LOGGER);
+
+ this.configuration = (ConfigurationComponent)
AuxiliaryComponentManager
+
.getInstance().getComponent(ComponentNames.CONFIG);
+
+ zebedeeExecutable = configuration
+ .getProperty("service.mp.flow.zebedee");
+ inPortBase = Integer.parseInt(configuration
+ .getProperty("service.mp.flow.inPort"));
+ betweenPortBase = Integer.parseInt(configuration
+ .getProperty("service.mp.flow.betweenPort"));
+ maxConn = Integer.parseInt(configuration
+ .getProperty("service.mp.flow.max_conn"));
}
-
- //return the singleton instance.
- return instance;
- }
-
- /**
- *
- * @param inPort The zebedee port at flow MP side where nfreplay should
dump flow into (inPortBase + key).
- * @param clientIP The flow subscribers ip address.
- * @param outPort The port on wich the client wants to receive the
flows. This port is supplied by the subscriber.
- * @param betweenPort Port used by zebedee to setup connection
(betweenPortBase + key)
- * @return The command to be executed for the tunnel to be set up.
- */
- private String getTunnelCommand(Integer inPort, String clientIP, Integer
outPort, Integer betweenPort) {
- return zebedeeExecutable + " -z 0 -u -d -l " + inPort + ":" +
clientIP + ":" + outPort + " -T " + betweenPort + " -x \"udptimeout 5\"";
- }
-
- /**
- *
- * @param key Unique key identifying the client (supplied by the
service).
- * @param clientIP The flow subscribers ip address.
- * @param outPort The port on wich the client wants to receive the
flows. This port is supplied by the subscriber.
- * @throws IOException When the program execution failed.
- * @throws SystemException
- */
- public Integer startTunnel(String clientIP, Integer outPort) throws
IOException, SystemException {
- //Get a new unique key
- Integer key = newKey();
-
- logger.debug("ZebedeeControl: starting tunnel with key " + key + ".");
-
- //get the commandline options formatted.
- String cmd =
getTunnelCommand(inPortBase+key,clientIP,outPort,betweenPortBase+key);
-
- //Check if this process doesn't alread exist, if so, kill it.
- if(processList.containsKey(key)) {
- stopTunnel(key);
+
+ /**
+ * Singleton static access method. Creates an instance of this class
if
+ * there is none, and returns it. Returns a running thread.
+ *
+ * @return the singleton instance (a running ZebedeeControl thread
+ * instance).
+ * @throws SystemException
+ * if configuration items can not be read.
+ */
+ public static ZebedeeControl getInstance() throws SystemException {
+ // If there's no instance, create it, and start it's thread.
+ if (instance == null) {
+ // create an instance (singleton).
+ instance = new ZebedeeControl();
+ // create a thread for this zebedee control instance.
+ Thread zebedeeControlThread = new Thread(instance);
+ // start the thread (calls the run method).
+ zebedeeControlThread.start();
+ }
+
+ // return the singleton instance.
+ return instance;
}
- //Run the process
- Process newProcess = Runtime.getRuntime().exec(cmd);
-
- //Put this key,process combination in the processList, and send a
keepalive for this key.
- processList.put(key, newProcess);
- keepAlive(key);
-
- return key;
- }
-
- /**
- * Stop a running tunnel (kills the zebedee process).
- *
- * @param key Unique key identifying the client (supplied by the
service).
- * @throws SystemException
- */
- public void stopTunnel(Integer key) throws SystemException {
+
+ /**
+ *
+ * @param inPort
+ * The zebedee port at flow MP side where nfreplay should
dump
+ * flow into (inPortBase + key).
+ * @param clientIP
+ * The flow subscribers ip address.
+ * @param outPort
+ * The port on wich the client wants to receive the flows.
This
+ * port is supplied by the subscriber.
+ * @param betweenPort
+ * Port used by zebedee to setup connection
(betweenPortBase +
+ * key)
+ * @return The command to be executed for the tunnel to be set up.
+ */
+ private String getTunnelCommand(Integer inPort, String clientIP,
+ Integer outPort, Integer betweenPort) {
+ return zebedeeExecutable + " -z 0 -u -d -l " + inPort + ":" +
clientIP
+ + ":" + outPort + " -T " + betweenPort + " -x
\"udptimeout 5\"";
+ }
+
+ /**
+ *
+ * @param key
+ * Unique key identifying the client (supplied by the
service).
+ * @param clientIP
+ * The flow subscribers ip address.
+ * @param outPort
+ * The port on wich the client wants to receive the flows.
This
+ * port is supplied by the subscriber.
+ * @throws IOException
+ * When the program execution failed.
+ * @throws SystemException
+ */
+ public Integer startTunnel(String clientIP, Integer outPort)
+ throws IOException, SystemException {
+ // Get a new unique key
+ Integer key = newKey();
+
+ logger.debug("ZebedeeControl: starting tunnel with key " +
key + ".");
+
+ // get the commandline options formatted.
+ String cmd = getTunnelCommand(inPortBase + key, clientIP,
outPort,
+ betweenPortBase + key);
+
+ // Check if this process doesn't alread exist, if so, kill it.
+ if (processList.containsKey(key)) {
+ stopTunnel(key);
+ }
+ // Run the process
+ Process newProcess = Runtime.getRuntime().exec(cmd);
+
+ // Put this key,process combination in the processList, and
send a
+ // keepalive for this key.
+ processList.put(key, newProcess);
+ keepAlive(key);
+
+ return key;
+ }
+
+ /**
+ * Stop a running tunnel (kills the zebedee process).
+ *
+ * @param key
+ * Unique key identifying the client (supplied by the
service).
+ * @throws SystemException
+ */
+ public void stopTunnel(Integer key) throws SystemException {
logger.debug("ZebedeeControl: stopping tunnel with key " +
key + ".");
- //Get the process that needs to be killed
+ // Get the process that needs to be killed
Process processToKill = processList.get(key);
- //Destroy (hard-kill) the process
+ // Destroy (hard-kill) the process
processToKill.destroy();
- //Remove the key from the processList and the keepAliveList
+ // Remove the key from the processList and the keepAliveList
processList.remove(key);
keepAliveList.remove(key);
ConfigFileWriter.delete(key);
- }
+ }

- /**
- * Infinate loop wich checks the keepalive times of the active tunnels.
- * @see Runnable.run
- */
- public void run() {
- // Infinate loop
- while (true) {
- try {
- Thread.sleep(SLEEPTIME);
- } catch (InterruptedException e) {
- e.printStackTrace();
- logger.error("ZebedeeControl: InterruptedException! " +
e.getMessage());
- }
- //run the checkForTimeouts method to check for timeouts, and to
close timed-out tunnels
- try {
+ /**
+ * Infinate loop wich checks the keepalive times of the active
tunnels.
+ *
+ * @see Runnable.run
+ */
+ public void run() {
+ // Infinate loop
+ while (true) {
+ try {
+ Thread.sleep(SLEEPTIME);
+ } catch (InterruptedException e) {
+ logger.error("ZebedeeControl:
InterruptedException! "
+ + e.getMessage());
+ for (StackTraceElement ste :
e.getStackTrace()) {
+ logger.error(ste.toString());
+ }
+ }
+ // run the checkForTimeouts method to check for
timeouts, and to
+ // close timed-out tunnels
+ try {
checkForTimeouts();
} catch (SystemException e) {
- e.printStackTrace();
- logger.error("ZebedeeControl:
SystemException! " + e.getMessage());
+ logger.error("ZebedeeControl:
SystemException! "
+ + e.getMessage());
+ for (StackTraceElement ste :
e.getStackTrace()) {
+ logger.error(ste.toString());
+ }
}
- }
- }
-
- /**
- * Updates the last keepalive timestamp for this tunnel (identified by
key).
- *
- * @param key The unique key for the clients tunnel connection.
- */
- public void keepAlive(Integer key) {
- logger.debug("ZebedeeControl: keeping alive tunnel with key "
+ key + ".");
- // current time
+ }
+ }
+
+ /**
+ * Updates the last keepalive timestamp for this tunnel (identified
by key).
+ *
+ * @param key
+ * The unique key for the clients tunnel connection.
+ */
+ public void keepAlive(Integer key) {
+ logger.debug("ZebedeeControl: keeping alive tunnel with key "
+ key
+ + ".");
+ // current time
Long now = (Long) System.currentTimeMillis();
-
- //add or update this key with the current time
+
+ // add or update this key with the current time
keepAliveList.put(key, now);
- }
-
- /**
- * Checks the keepAliveList list for timed-out tunnels and closes them.
- * @throws SystemException
- */
- private void checkForTimeouts() throws SystemException {
- logger.debug("ZebedeeControl: checking for timeouts.");
- // temporary list with timed out tunnel connections
- ArrayList<Integer> tunnelsToClose = new ArrayList<Integer>();
-
- // current time
- Long now = (Long) System.currentTimeMillis();
-
- // Loop through all active tunnels
- // to check their keepalive times
- for (Integer key : keepAliveList.keySet()) {
- // if time between keepalives is getting to large,
- // add it to the list of tunnels to be closed
- if (now - keepAliveList.get(key) > MAX_KEEPALIVE) {
- logger.debug("ZebedeeControl: tunnel with key " + key + " has
timed out.");
- tunnelsToClose.add(key);
- }
- }
-
- // Loop through all tunnels to close
- // and execute tunnel closing code,
- // and remove them from the keepAliveList
- // list
- for (Integer key : tunnelsToClose) {
- stopTunnel(key);
- keepAliveList.remove(key);
- }
- }
-
- /**
- * Find a new key, that is not already in use.
- * @return a new unique key
- */
- private synchronized Integer newKey() {
- Integer proposal = 1;
- while(proposal < 100 && keyList.contains(proposal)) {
- proposal ++;
}
- keyList.add(proposal);
-
- return proposal;
- }
+
+ /**
+ * Checks the keepAliveList list for timed-out tunnels and closes
them.
+ *
+ * @throws SystemException
+ */
+ private void checkForTimeouts() throws SystemException {
+ logger.debug("ZebedeeControl: checking for timeouts.");
+ // temporary list with timed out tunnel connections
+ ArrayList<Integer> tunnelsToClose = new ArrayList<Integer>();
+
+ // current time
+ Long now = (Long) System.currentTimeMillis();
+
+ // Loop through all active tunnels
+ // to check their keepalive times
+ for (Integer key : keepAliveList.keySet()) {
+ // if time between keepalives is getting to large,
+ // add it to the list of tunnels to be closed
+ if (now - keepAliveList.get(key) > MAX_KEEPALIVE) {
+ logger.debug("ZebedeeControl: tunnel with key
" + key
+ + " has timed out.");
+ tunnelsToClose.add(key);
+ }
+ }
+
+ // Loop through all tunnels to close
+ // and execute tunnel closing code
+ for (Integer key : tunnelsToClose) {
+ stopTunnel(key);
+ }
+ }
+
+ /**
+ * Find a new key, that is not already in use.
+ *
+ * @return a new unique key, or -1 when failed (max clients reached)
+ */
+ private synchronized Integer newKey() {
+ Integer proposal = 1;
+ while (proposal < maxConn && keyList.contains(proposal)) {
+ proposal++;
+ }
+ // if maxConn reached && keyList.contains(proposal), we're
full
+ if (keyList.contains(proposal)) {
+ return -1;
+ }
+
+ // add the key, return it.
+ keyList.add(proposal);
+
+ return proposal;
+ }
+
+ public String generateAnonymizingKey() {
+ String characters = "abcdefghijklmnopqrstuvwxyz"
+ + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
"01234567890";
+ String randomKey = "";
+ while (randomKey.length() < 32) {
+ char nextChar = characters.charAt((int)
(Math.random() * characters.length()));
+ randomKey = randomKey + nextChar;
+ }
+ return randomKey;
+ }
}



  • r2054 - trunk/perfsonar/src/org/perfsonar/service/measurementPoint/flowType, svnlog, 02/12/2007

Archive powered by MHonArc 2.6.16.

Top of Page