Ports information in Floodlight

Question

How can we get the port’s information in Floodlight?

Solution

  • The Floodlight use a ImmutablePort class to represent a switch port and a IOFSwitch class has a Portmanager which will manager all ImmutablePort.

  • The content of ImmutablePort is the same as what it described in Openflow specification 1.0.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    public class ImmutablePort {
    private final short portNumber;
    private final byte[] hardwareAddress;
    private final String name;
    private final EnumSet<OFPortConfig> config;
    private final boolean portStateLinkDown;
    private final OFPortState stpState;
    private final EnumSet<OFPortFeatures> currentFeatures;
    private final EnumSet<OFPortFeatures> advertisedFeatures;
    private final EnumSet<OFPortFeatures> supportedFeatures;
    private final EnumSet<OFPortFeatures> peerFeatures;
    ....
  • The Portmanger provide some API to allow other object to fetch the ImmutablePort.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
public ImmutablePort getPort(String name) {
if (name == null) {
throw new NullPointerException("Port name must not be null");
}
lock.readLock().lock();
try {
return portsByName.get(name.toLowerCase());
} finally {
lock.readLock().unlock();
}
}

public ImmutablePort getPort(Short portNumber) {
lock.readLock().lock();
try {
return portsByNumber.get(portNumber);
} finally {
lock.readLock().unlock();
}
}

public List<ImmutablePort> getPorts() {
lock.readLock().lock();
try {
return portList;
} finally {
lock.readLock().unlock();
}
}

public List<ImmutablePort> getEnabledPorts() {
lock.readLock().lock();
try {
return enabledPortList;
} finally {
lock.readLock().unlock();
}
}
  • Since the Portmanager is a private member of IOFSwitch, you can’t directly use it. You must use the API provied by IOFSwitch to interact with Portmanager.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
@Override
@JsonIgnore
public Collection<ImmutablePort> getEnabledPorts() {
return portManager.getEnabledPorts();
}

@Override
@JsonIgnore
public Collection<Short> getEnabledPortNumbers() {
return portManager.getEnabledPortNumbers();
}

@Override
public ImmutablePort getPort(short portNumber) {
return portManager.getPort(portNumber);
}

@Override
public ImmutablePort getPort(String portName) {
return portManager.getPort(portName);
}

@Override
@JsonProperty("ports")
public Collection<ImmutablePort> getPorts() {
return portManager.getPorts();
}

Example

Assume the type of sw is IOFSwitch.

1
2
3
4
5
6
Collection<ImmutablePort> swPorts = sw.getPorts();
Iterator<ImmutablePort> it = swPorts.iterator();
while(it.hasNext()){
ImmutablePort port = it.next();
//do something
}