wwndesc  1.0-76
IBMSVCDescription.java
Go to the documentation of this file.
1 /* smallfoot.org is owned by allan.clark */
2 package org.smallfoot.wwn;
3 
4 import java.math.BigInteger;
5 
6 /**
7  * @file
8  */
9 
10 /**
11  * IBMSVCDescription (ie SVCe0_Node0E_Port1) breaks out the SVC number, node, and port of a WWPN; it does not see where two nodes of a SVC are related
12  */
14 {
15  /** @copydoc WWNDesc#WWNDesc(String) */
16  public IBMSVCDescription(String wwn)
17  {
18  super(wwn);
19  }
20  /** @copydoc WWNDesc#WWNDesc(boolean,String) */
21  public IBMSVCDescription(boolean brief, String wwn)
22  {
23  super(brief, wwn);
24  }
25 
26  /**
27  * If this class matches or describes the given WWN, returns a new instance of this class loaded with the given WWN.
28  *
29  * @return new instance of this class, or null if the given wwn does not match this class
30  * @param strong is used to show only those patterns we're 100% certain about: this class is a strong representation of 505076801*, but a weak representation of all 50507680* (notice that the last nibble is fuzzy, meaning we could get duplicate names)
31  * @param brief is used to ask for a shorter description: a more concise nickname or alias
32  * @param wwn the WWN (WWPN or WWNN, but typically WWPN) to match
33  */
34  public static WWNDesc getDesc(boolean strong, boolean brief, String wwn)
35  {
36  return getDesc(strong, brief, wwn, DevRole.max()-1);
37  }
38  /**
39  * @copydoc #getDesc(boolean, boolean, String)
40  * @param role Role (Initiator/Switch/Target) to check for
41  */
42  public static WWNDesc getDesc (boolean strong, boolean brief, String wwn, int role)
43  {
44  if (!isA(role))
45  return null;
46  else if ((strong) && (wwn.matches("5005076801.*")) )
47  return new IBMSVCDescription(brief, wwn);
48  else if (wwn.matches("500507680.*"))
49  return new IBMSVCDescription(brief, wwn);
50  else
51  return null;
52  }
53 
54  /**
55  * return a description or alias for this WWN; if brief is set to true during the call to getDesc(), then a shorter description or alias will be returned
56  *
57  * @see getDesc(boolean,boolean,String)
58  *
59  * @return generated alias or nickname for the WWN
60  */
61  public String toString()
62  {
63  String res = super.toString();
64  if (null == res) res = "";
65 
66  /* convert 5005076801P0xxNN into SVCxx_NodeNN_PortP */
67  /* for example start with 5005076801:30ee81 and produce SVCee_Node81_Port3 */
68  BigInteger serDirPort[] = wwn.divideAndRemainder(new BigInteger("1000000",16));
69  /* serDirPort[0]=5005076801 ; serDirPort[1]=30ee81 */
70 
71  BigInteger portChassisNode[] = serDirPort[1].divideAndRemainder(new BigInteger("10000",16));
72  /* portChassisNode[0]=30 ; portChassisNode[1]=ee81 */
73  BigInteger chassisNode[] = portChassisNode[1].divideAndRemainder(new BigInteger("100",16));
74 
75  return res + String.format("SVC%02x_%s%02X_%s%s",chassisNode[0].intValue(), (brief ? "N" : "Node"), chassisNode[1].intValue(), (brief ? "P" : "Port"), portChassisNode[0].intValue()/16);
76  }
77 }
static WWNDesc getDesc(boolean strong, boolean brief, String wwn, int role)
If this class matches or describes the given WWN, returns a new instance of this class loaded with th...
IBMSVCDescription(boolean brief, String wwn)
create an instance with the given WWN.
static boolean isA(int role)
convenience function to use bit-masks to check for membership in this role
Definition: WWNDesc.java:158
DevRole role
role of the device: Target, Switch, Initiator
Definition: WWNDesc.java:24
String toString()
return a description or alias for this WWN; if brief is set to true during the call to getDesc()...
boolean brief
whether a more brief output should be offered in toString() (ie the difference between "VMax-HK192601...
Definition: WWNDesc.java:22
static int max
global singleton to keep track of the max DevRole.value so far
Definition: DevRole.java:21
IBMSVCDescription (ie SVCe0_Node0E_Port1) breaks out the SVC number, node, and port of a WWPN; it doe...
IBMSVCDescription(String wwn)
create an instance with brief set to false.
This class seeks to provide simple bitfield type-checking of a device in a fabric so that I can use t...
Definition: DevRole.java:18
WWNDesc is the basic generic class from which each vendor-specific pattern is built upon; similar to ...
Definition: WWNDesc.java:19
simple pass-thru class to define internal value for a Target in an idempotent way ...
Definition: WWNDesc.java:139
BigInteger wwn
the WWN that the instance tried to describe
Definition: WWNDesc.java:21
static WWNDesc getDesc(boolean strong, boolean brief, String wwn)
If this class matches or describes the given WWN, returns a new instance of this class loaded with th...