wwndesc  1.0-76
AIXLPARServerDescription.java
1 /* smallfoot.org is owned by allan.clark */
2 package org.smallfoot.wwn;
3 
4 import java.math.BigInteger;
5 
6 /**
7  * AIXLPARServerDescription (ie LPAR-012345:0) breaks out the uniqueness number and port index from the WWPN. There may be difficulty here in determining whether a device is a switch or a NPIV bladecenter for servers; it's not obvious from the WWPNs
8  */
10 {
11  /** @copydoc WWNDesc#WWNDesc(String) */
13  {
14  super(wwn);
15  }
16 
17  /**
18  * If this class matches or describes the given WWN, returns a new instance of this class loaded with the given WWN.
19  *
20  * @return new instance of this class, or null if the given wwn does not match this class
21  * @param strong used to restrict matching to strong-matches only. This is a weak-confidence description, so will return null for strong-only matching
22  * @param brief is used to ask for a shorter description: a more concise nickname or alias
23  * @param wwn the WWN (WWPN or WWNN, but typically WWPN) to match
24  */
25  public static WWNDesc getDesc(boolean strong, boolean brief, String wwn)
26  {
27  return getDesc(strong, brief, wwn, DevRole.max()-1);
28  }
29  /**
30  * @copydoc #getDesc(boolean, boolean, String)
31  * @param role Role (Initiator/Switch/Target) to check for
32  */
33  public static WWNDesc getDesc (boolean strong, boolean brief, String wwn, int role)
34  {
35  if (!isA(role))
36  return null;
37  else if (strong)
38  return null;
39  else if (wwn.matches("c05076[0-9a-f]{10}"))
40  return new AIXLPARServerDescription(brief, wwn);
41  else
42  return null;
43  }
44 
45  /** @copydoc WWNDesc#WWNDesc(boolean,String) */
46  public AIXLPARServerDescription(boolean brief, String wwn)
47  {
48  super(brief, wwn);
49  }
50  /**
51  * 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
52  *
53  * @see getDesc(boolean,boolean,String)
54  *
55  * @return generated alias or nickname for the WWN
56  */
57  public String toString()
58  {
59  String res = super.toString();
60  if (null == res) res = "";
61 
62  /* for example start with c050760123450010 or c05076:012345:0010 broken apart -- I've noticed that the LPAs in a given frame, perhaps by convention only, have consistent 12 digits (including OUI) and differing last 16 bits that almost appear to be odd/even split amongst fabrics */
63 
64  BigInteger ouiSerPort[] = wwn.divideAndRemainder(new BigInteger("10000",16));
65 
66  /* our example now has ouiSerPort = { [c05076:012345],[0010] } */
67  BigInteger ouiSer[] = ouiSerPort[0].divideAndRemainder(new BigInteger("1000000",16));
68 
69  /* our example now has ouiSer = { [c05076], [012345] } */
70 
71  return res + String.format("LPAR-%06x:%04x",ouiSer[1].intValue(),ouiSerPort[1].intValue() );
72  }
73 
74  /**
75  * describe the WWPN's unique port label/index
76  *
77  * @return the unique name for the port WWPN
78  */
79  public String descPort()
80  {
81  BigInteger serPort[] = wwn.divideAndRemainder(new BigInteger("10000",16));
82  return String.format("%04x",serPort[1].intValue());
83  }
84 }
String descPort()
describe the WWPN's unique port label/index
String toString()
return a description or alias for this WWN; if brief is set to true during the call to getDesc()...
AIXLPARServerDescription (ie LPAR-012345:0) breaks out the uniqueness number and port index from the ...
static boolean isA(int role)
convenience function to use bit-masks to check for membership in this role
Definition: WWNDesc.java:106
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...
DevRole role
role of the device: Target, Switch, Initiator
Definition: WWNDesc.java:24
AIXLPARServerDescription(String wwn)
create an instance with brief set to false.
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
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
AIXLPARServerDescription(boolean brief, String wwn)
create an instance with the given WWN.
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 Initiator in an idempotent way ...
Definition: WWNDesc.java:87
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...
BigInteger wwn
the WWN that the instance tried to describe
Definition: WWNDesc.java:21