wwndesc  1.0-76
CiscoSwitchDescription.java
1 /* smallfoot.org is owned by allan.clark */
2 package org.smallfoot.wwn;
3 
4 import java.math.BigInteger;
5 
6 /**
7  * CiscoSwitchDescription (ie Cisco-001560-0123456: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) */
12  public CiscoSwitchDescription(String wwn)
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("2[0-9a-f]{3}000dec[0-9a-f]{6}"))
40  return new CiscoSwitchDescription(brief, wwn);
41  else if (wwn.matches("2[0-9a-f]{3}001560[0-9a-f]{6}"))
42  return new CiscoSwitchDescription(brief, wwn);
43  else if (wwn.matches("2[0-9a-f]{3}00215a[0-9a-f]{6}"))
44  return new CiscoSwitchDescription(brief, wwn);
45  else if (wwn.matches("2[0-9a-f]{3}547fee[0-9a-f]{6}"))
46  return new CiscoSwitchDescription(brief, wwn);
47  else
48  return null;
49  }
50 
51  /** @copydoc WWNDesc#WWNDesc(boolean,String) */
52  public CiscoSwitchDescription(boolean brief, String wwn)
53  {
54  super(brief, wwn);
55  }
56  /**
57  * 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
58  *
59  * @see getDesc(boolean,boolean,String)
60  *
61  * @return generated alias or nickname for the WWN
62  */
63  public String toString()
64  {
65  String res = super.toString();
66  if (null == res) res = "";
67 
68  /* for example start with 20:13:00:15:60:12:34:56 or 2:013:001560:123456 broken apart */
69 
70  BigInteger portOuiSer[] = wwn.divideAndRemainder(new BigInteger("1000000",16));
71 
72  /* our example now has portOuiSer = { [2:013:001560],[123456] } */
73  BigInteger portOui[] = portOuiSer[0].divideAndRemainder(new BigInteger("1000000",16));
74 
75  /* our example now has portOui = { [2:013], [001560] } */
76 
77  if (brief)
78  return res + String.format("Cisco-%06x:%d",portOuiSer[1].intValue(),portOui[0].intValue() % (1 << 12) );
79  else
80  return res + String.format("Cisco-%06x-%06x:%d",portOui[1].intValue(),portOuiSer[1].intValue(),portOui[0].intValue() % (1 << 12) );
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("1000000000000",16));
91  return String.format("%03x",serPort[0].intValue() % (1 << 12));
92  }
93 }
simple pass-thru class to define internal value for a Switch in an idempotent way ...
Definition: WWNDesc.java:113
CiscoSwitchDescription (ie Cisco-001560-0123456:0) breaks out the uniqueness number and port index fr...
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...
String descPort()
describe the WWPN's unique port label/index
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
static int max
global singleton to keep track of the max DevRole.value so far
Definition: DevRole.java:21
String toString()
return a description or alias for this WWN; if brief is set to true during the call to getDesc()...
CiscoSwitchDescription(boolean brief, String wwn)
create an instance with the given WWN.
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
CiscoSwitchDescription(String wwn)
create an instance with brief set to false.
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
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...