wwndesc  1.0-76
CiscoUCSServerDescription.java
1 /* smallfoot.org is owned by allan.clark */
2 package org.smallfoot.wwn;
3 
4 import java.math.BigInteger;
5 
6 /**
7  * CiscoUCSServerDescription (ie CiscoUCS-012-123:0) breaks out the uniqueness number and port index from the WWPN of a UCS-served physical host. I do tend to see 20000025b5hhhfnnn such that:
8  * <ul>
9  * <li>hhh is a three-digit host index</li>
10  * <li>f is either 0 or 1 based on fabric A or B</li>
11  * <li>nnn is a three-digit server index</li>
12  * </ul>
13  *
14  * The thing to remember about UCS is that the WWPN are entirely user-defined, are are UUIDs, so this is merely a convention. It might fall apart on the next user!
15  */
17 {
18  /** @copydoc WWNDesc#WWNDesc(String) */
20  {
21  super(wwn);
22  }
23 
24  /**
25  * If this class matches or describes the given WWN, returns a new instance of this class loaded with the given WWN.
26  *
27  * @return new instance of this class, or null if the given wwn does not match this class
28  * @param strong used to restrict matching to strong-matches only. This is a weak-confidence description, so will return null for strong-only matching
29  * @param brief is used to ask for a shorter description: a more concise nickname or alias
30  * @param wwn the WWN (WWPN or WWNN, but typically WWPN) to match
31  */
32  public static WWNDesc getDesc(boolean strong, boolean brief, String wwn)
33  {
34  return getDesc(strong, brief, wwn, DevRole.max()-1);
35  }
36  /**
37  * @copydoc #getDesc(boolean, boolean, String)
38  * @param role Role (Initiator/Switch/Target) to check for
39  */
40  public static WWNDesc getDesc (boolean strong, boolean brief, String wwn, int role)
41  {
42  if (!isA(role))
43  return null;
44  else if (strong)
45  return null;
46  else if (wwn.matches("20000025b5[0-9a-f]{6}"))
47  return new CiscoUCSServerDescription(brief, wwn);
48  else if (wwn.matches("2[0-9a-f]{3}002a6a[0-9a-f]{6}"))
49  return new CiscoSwitchDescription(brief, wwn);
50  else
51  return null;
52  }
53 
54  /** @copydoc WWNDesc#WWNDesc(boolean,String) */
55  public CiscoUCSServerDescription(boolean brief, String wwn)
56  {
57  super(brief, wwn);
58  }
59  /**
60  * 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
61  *
62  * @see getDesc(boolean,boolean,String)
63  *
64  * @return generated alias or nickname for the WWN
65  */
66  public String toString()
67  {
68  String res = super.toString();
69  if (null == res) res = "";
70 
71  /* for example start with 20:00:00:25:b5:12:34:56 or 2:000:0025b5:123456 broken apart */
72 
73  BigInteger portOuiSerInd[] = wwn.divideAndRemainder(new BigInteger("1000000",16));
74 
75  /* our example now has portOuiSerInd = { [2000:0025b5],[123456] } */
76  BigInteger serInd[] = portOuiSerInd[1].divideAndRemainder(new BigInteger("1000",16));
77 
78  /* our example now has serInd = { [123], [456] } */
79 
80  return res + String.format("CiscoUCS-%03x:%03x",serInd[0].intValue(),serInd[1].intValue());
81  }
82 
83  /**
84  * describe the WWPN's unique port label/index
85  *
86  * @return the unique name for the port WWPN
87  */
88  public String descPort()
89  {
90  BigInteger serPort[] = wwn.divideAndRemainder(new BigInteger("1000",16));
91  return String.format("%03x",serPort[1].intValue());
92  }
93 }
simple pass-thru class to define internal value for a Switch in an idempotent way ...
Definition: WWNDesc.java:113
String descPort()
describe the WWPN's unique port label/index
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...
CiscoSwitchDescription (ie Cisco-001560-0123456:0) breaks out the uniqueness number and port index fr...
CiscoUCSServerDescription(String wwn)
create an instance with brief set to false.
DevRole role
role of the device: Target, Switch, Initiator
Definition: WWNDesc.java:24
boolean brief
whether a more brief output should be offered in toString() (ie the difference between "VMax-HK192601...
Definition: WWNDesc.java:22
String toString()
return a description or alias for this WWN; if brief is set to true during the call to getDesc()...
static int max
global singleton to keep track of the max DevRole.value so far
Definition: DevRole.java:21
CiscoUCSServerDescription(boolean brief, String wwn)
create an instance with the given WWN.
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...
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
CiscoUCSServerDescription (ie CiscoUCS-012-123:0) breaks out the uniqueness number and port index fro...
static boolean isA(int role)
convenience function to use bit-masks to check for membership in this role
Definition: WWNDesc.java:132
BigInteger wwn
the WWN that the instance tried to describe
Definition: WWNDesc.java:21