Like this article? We recommend
Appendix A
This appendix presents some code skeletons that show how you could possibly implement a QoS solution with Sun MC 3.0 and Solaris Bandwidth Manager 1.6 software.
Pseudo Code
The following code boxes illustrate a pseudo code for a QoS solution.
/* ________________________________________________________________________________ QoSSBM : Quality Of Service Policy Based Network and Systems Management Policy Decision Point - PDP DESC: This Skeleton Prototype, polls for agent stats from the Sun Server which is running a Java Agent using the Sun MCI 3.0 API Libaries. The user is expected to enter a policy, which is composed of a Condition, the condition for this skeleton code, is that cpu utilization exceeds 90%. Once this condition evaluates to TRUE, this Policy Decision Point, creates a class object for each of the following classes: Platinum - 50% Gold - 25% Silver - 15% Bronze -10% and replaces this with lower bandwidth percentages. An alternative simply retrieves the QInterface object and lowers the entire interface bandwidth, thereby controlling the PEP's input rate, thereby controlling the amount of traffic sent to the servers. ________________________________________________________________________________ */ */ import Java.util.*; import Java.net.*; import Java.lang.reflect.*; import Java.io.*; import com.sun.jaw.reference.query.*; import com.sun.jaw.reference.client.adaptor.*; import com.sun.jaw.reference.client.mo.*; import com.sun.jaw.impl.adaptor.security.*; import com.sun.jaw.impl.adaptor.http.*; import Java.util.Vector; import Java.io.PrintWriter; import com.sun.jaw.reference.common.*; import com.sun.ba.common.*; import com.sun.ba.mo.*; import com.sun.ba.events.*; import com.sun.ba.config.*; public class QoSSBM implements QConstants { private static void usage() { System.err.println("Usage: Java QoSSBM [PEP]"); } public void reconfigurePEP( QDynamicConfMO runningConf) throws InstanceAlreadyExistException, InstanceNotFoundException { try{ ServerSocket PEPsock = new ServerSocket(3001); Loop: while (true) { Socket pepsocket=PEPsock.accept(); BufferedReader pepin = new BufferedReader(new InputStreamReader(pep socket.getInputStream() )); System.out.println("--------------------- data from agent -------------- ----"); System.out.println(pepin.readLine()); if Agent cpu utilization data < threshold{ continue Loop: } /* Create the new lower b/w classes that will replace existing classes definitions Note these class names must match the class definitions in file:deepak.ba.conf-2.27.5pm */ System.out.println("creating modified classes for PEP reconfigura- tion...\n"); try { /* Platinum Class reconfiguration */ QIfName hmein = new QIfName("hme2_in"); System.out.println("QIfName hmein = " + hmein); QClassName pn = new QClassName(hmein, "platclass"); System.out.println("QClassName pn =" + pn); QClass platcl = runningConf.performGetClass(pn); System.out.println("QClass platcl="+platcl); platcl.setName("platclass"); platcl.setBandwidth(40); platcl.setPriority((byte) 1); System.out.println(" Downloading Reprovisioned Class information to PEP"); pn = runningConf.performModifyClass(pn,platcl); System.out.println(" Modified pn=" + pn); /* Gold Class reconfiguration */ QClassName gn = new QClassName(hmein, "goldclass"); QClass goldcl = new QClass(); |
PEP Agent Pseudo Code
This is the feedback of a server load to the Policy server via socket connection.
/* __________________________________________________________________________ PEP: Policy Enforcement Point Server Agent DESC: This Java client code, runs on the server as an PEP agent. This agent continually sends feedback peformance data to the Policy Server, which then decides what action to take. This is a skeleton code, that still needs to have code written to open another socket that accepts reconfiguration commands from the PDP. Some of this code was borrowed from the Sun MC 3.0 examples. Reconfiguration of this pep is currently via rsh system calls. AUTHOR: Deepak Kakadia, Staff Engineer, Enterprise Services, Sun Microsystems DATE: March 2 2001 __________________________________________________________________________ */ import Java.net.*; import Java.io.*; import com.sun.symon.base.client.*; import Java.util.Vector; public class PEP extends SMRawDataResponseAdapter { Socket pdpsock = null; InputStream pdpin =null; PrintStream pdpout =null; public PEP( String server_name, int server_port, int agent_port, String user, String password ) throws Exception { try { String publicKey = "687a8398ad4a85077d33b72a94e16ffde0c4ba023e" + "9c9ba77b247cc25bd3cd0015bc24b7429916751e68" + "1fd02e5ad6eb5345eb7c75b39a1c304e0f000846aa" + "470b755b0640af974e7fc70daa6191dff6efa31a09" + "431bb5e9848b7dc4cf4b97e1dbca31792d2860ca5a" + "5990dfb369e1bcf296274a4e4984c8089329679dd3" + "04cd"; System.out.println(" Connecting to local Sun MC 3.0 Agent...."); SMLogin obj = new SMLogin(); obj.connect(server_name, server_port, user, password, publicKey); System.out.println("Successfully Connected and Authenticated"); System.out.println(" connecting to pdp server - angeli ..."); pdpsock = new Socket("angeli",3001); pdpin = pdpsock.getInputStream(); /* future to process reconfiguration commands from PDP */ pdpout =new PrintStream(pdpsock.getOutputStream()); /* polling server resource utilization data to PDP */ SMRawDataRequest req = obj.getRawDataRequest(); while(true) { String[] urlarr = new String[2]; urlarr[0] = "snmp://" + server_name + ":" + agent_port + "/mod/kernel-reader/cpu-detail/cpu-util/cpuUtilTable" + "/cpuUtilEntry/cpu_idle"; urlarr[1] = "snmp://" + server_name + ":" + agent_port + "/mod/kernel-reader/cpu-detail/cpu-util/cpuUtilTable/" + "cpuUtilEntry/cpu_user"; Vector urlvect = new Vector(); urlvect.addElement(urlarr[0]); urlvect.addElement(urlarr[1]); req.getURLValue(urlvect, "2", this, this); System.out.println("sleeping..."); Thread.sleep(2000); } } catch (Exception e) { System.out.println(e.getMessage()); } } public void getURLResponse( SMRequestStatus status, Vector dat, Object identifier) { int error = status.getReturnCode(); if (error == SMErrorCode.SUCCESS) { if (dat.size() != 2) { System.out.println("Incorrect data returned. size =" + dat.size()); } else { for (int i = 0; i < dat.size(); i++) { Vector row = (Vector) dat.elementAt(i); pdpout.println(row.elementAt(0)); for (int j = 0; j < row.size() ; j++) { if (i == 0) { System.out.println("Sending Feedback to PDP -% CPU Idle time for cpu(s): " + row.elementAt(j)); pdpout.println(row.elementAt(j)); } else{ System.out.println("% CPU User time for cpu(s): " + row.elementAt(j)); } } } } } else { // Failure // The various error codes as in SMErrorCode may be reported here System.out.println("Error code = " + error + " " + "Msg Text = " + status.getMessageText() + " " + "Exception = " + (status.getException()).getMessage()); } } private static void usage() { System.out.println( "usage: Java PEP " + "server_name server_port agent_port user password"); } public static void main(String[] args) throws Exception { if ( args.length != 5) { usage(); System.exit(1); } else { try{ new PEP (args[0], new Integer(args[1]).intValue(), new Integer(args[2]).intValue(), args[3], args[4]); System.exit(0); } catch(Exception e){ e.printStackTrace(); } } } } |
< Back
Page 4 of 4