wwndesc  1.0-76
HDSModularDescription.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  * HDSModularDescription (ie HDS-D850-31787-CTL0-PortD) breaks out the model type, serial, and FA port from the WWPN
12  */
13 
15 {
16  /** @copydoc WWNDesc#WWNDesc(String) */
17  public HDSModularDescription(String wwn)
18  {
19  super(wwn);
20  }
21  /** @copydoc WWNDesc#WWNDesc(boolean,String) */
22  public HDSModularDescription(boolean brief, String wwn)
23  {
24  super(brief, wwn);
25  }
26 
27  /**
28  * If this class matches or describes the given WWN, returns a new instance of this class loaded with the given WWN.
29  *
30  * This function should correspond to HDSVSPDescription#getDesc(boolean, boolean, String)
31  * as both are redundant copies simply to avoid an error ustream being leaked out to the user
32  *
33  * @return new instance of this class, or null if the given wwn does not match this class
34  * @param strong is ignored: this class is a strong representation, not a weak one based on empirical matching, hence can always be used with confidence
35  * @param brief is used to ask for a shorter description: a more concise nickname or alias
36  * @param wwn the WWN (WWPN or WWNN, but typically WWPN) to match
37  */
38  public static WWNDesc getDesc(/* ignored */ boolean strong, boolean brief, String wwn)
39  {
40  return getDesc(strong, brief, wwn, DevRole.max()-1);
41  }
42  /**
43  * @copydoc #getDesc(boolean, boolean, String)
44  * @param role Role (Initiator/Switch/Target) to check for
45  */
46  public static WWNDesc getDesc (boolean strong, boolean brief, String wwn, int role)
47  {
48  if (!isA(role))
49  return null;
50  else if (wwn.startsWith("50060e8010"))
51  return new HDSModularDescription(brief, wwn);
52  else if (wwn.startsWith("50060e8"))
53  return new HDSVSPDescription(brief, wwn);
54  else
55  return null;
56  }
57 
58  /**
59  * 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
60  *
61  * @see getDesc(boolean,boolean,String)
62  *
63  * @return generated alias or nickname for the WWN
64  */
65  public String toString()
66  {
67  String res = super.toString();
68  if (null == res) res = "";
69  if (!brief) res += "HDS-";
70 
71  /**
72  * 010 TOM: HDS KA15062: breaks it up as N OOOOOO FFF S ssss P (N=5, OOOOOO = OUI, FFF = Family (010) ssss=Serial % 0x10000, P=Port (0-F)
73  * need to check against http://p2v.it/tools/wwndec/index.php?input=50060e8010139322
74  * need to check http://p2v.it/tools/wwndec/index.php?input=50060e8010139322
75  */
76 
77  /* for example start with 50060e8010139322 from HDS KB15062 */
78  BigInteger serDirPort = wwn.remainder(new BigInteger("1000000",16));
79 
80  /* our example now has 139322 - get the 3-nibble model code */
81  BigInteger modelDirPort[];
82  modelDirPort = serDirPort.divideAndRemainder(new BigInteger("100000",16)); /* modelDirPort[0] = 1, modelDirPort[1] = 39322 */
83 //System.out.println(String.format("split result: modelDirPort: %02x / %06x (%06d)", modelDirPort[0].intValue(), modelDirPort[1].intValue(), modelDirPort[1].intValue()));
84  int model = modelDirPort[0].intValue();
85 
86  BigInteger serialPort[] = modelDirPort[1].divideAndRemainder(new BigInteger("10",16)); /* serialPort[0] = 3932, serialPort[1] = 2 */
87  int serial = serialPort[0].intValue();
88  int iPort = serialPort[1].intValue();
89 //System.out.println(String.format("split result: model %02d serial %05x / %06d port %d", model, serial, serial, iPort));
90 
91  switch (model)
92  {
93  case 0: /* DF800H/EH */
94  res += "DF800H-";
95  serial -= 10000;
96  break;
97  case 1: /* DF850MH */
98  res += "DF850MH-";
99  serial -= 70000;
100  break;
101  case 2: /* DF800M/EM */
102  res += "DF800M-";
103  serial -= 10000;
104  break;
105  case 3: /* DF850S */
106  res += "DF850S-";
107  serial -= 70000;
108  break;
109  case 4: /* DF800S/ES/EXS */
110  res += "DF800ES-";
111  serial -= 10000;
112  break;
113  case 5: /* DF850XS */
114  res += "DF850XS-";
115  serial -= 70000;
116  break;
117  case 9: /* SA800 (The value is set to 9 if Serial# is 65536(decimal) or more) */
118  serialPort[0] = serialPort[0].add(new BigInteger("100000", 16));
119  /* fall-thru */
120  case 8: /* SA800 */
121  res += "SA800";
122  break;
123  case 0x0B: /* SA810 :A or B (The value is set to B if Serial# is 65536(decimal) or more) */
124  serialPort[0] = serialPort[0].add(new BigInteger("100000", 16));
125  /* fall-thru */
126  case 0x0A: /* SA810 */
127  res += "SA810";
128  break;
129  default: /* unknown */
130  res += String.format("HDSUnkn%03x-",model);
131  }
132 //System.out.println(String.format("munge result: model %02d serial %05x / %06d port %d", model, serial, serial, iPort));
133  if (serial < 0) serial += 0x10000;
134 //System.out.println(String.format("munge result: model %02d serial %05x / %06d port %d", model, serial, serial, iPort));
135 
136 
137  char port = 'A';
138  port += (iPort % 8);
139  int ctl = iPort / 8;
140 
141  /* our example now has 39322 - get the serial number */
142  //serialPort[0] = serialPort[0].subtract(new BigInteger("70000",10));
143  if (brief)
144  return res + String.format("%05d-%d%c",serial, ctl, port);
145  else
146  return res + String.format("%05d-CTL%d-Port%c",serial, ctl, port);
147  }
148 }
static boolean isA(int role)
convenience function to use bit-masks to check for membership in this role
Definition: WWNDesc.java:158
HDSModularDescription (ie HDS-D850-31787-CTL0-PortD) breaks out the model type, serial, and FA port from the WWPN.
DevRole role
role of the device: Target, Switch, Initiator
Definition: WWNDesc.java:24
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...
HDSVSPDescription (ie USPV-10098-CL2A) breaks out the model type, serial, and FA port from the WWPN...
boolean brief
whether a more brief output should be offered in toString() (ie the difference between "VMax-HK192601...
Definition: WWNDesc.java:22
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...
static int max
global singleton to keep track of the max DevRole.value so far
Definition: DevRole.java:21
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
HDSModularDescription(boolean brief, String wwn)
create an instance with the given WWN.
HDSModularDescription(String wwn)
create an instance with brief set to false.
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
String toString()
return a description or alias for this WWN; if brief is set to true during the call to getDesc()...