Indentation correction
diff --git a/src/main/java/net/floodlightcontroller/core/web/OFPortStatsEntryMod.java b/src/main/java/net/floodlightcontroller/core/web/OFPortStatsEntryMod.java
index 222f279..77dea99 100644
--- a/src/main/java/net/floodlightcontroller/core/web/OFPortStatsEntryMod.java
+++ b/src/main/java/net/floodlightcontroller/core/web/OFPortStatsEntryMod.java
@@ -7,17 +7,16 @@
@JsonSerialize(using = OFPortStatsEntrySerializer.class)
public class OFPortStatsEntryMod {
- private OFPortStatsEntry portStatsEntry = null;
+ private OFPortStatsEntry portStatsEntry = null;
- public OFPortStatsEntryMod() {
- }
+ public OFPortStatsEntryMod() {
+ }
- public OFPortStatsEntryMod(OFPortStatsEntry portStatsEntry) {
- this.portStatsEntry = portStatsEntry;
- }
+ public OFPortStatsEntryMod(OFPortStatsEntry portStatsEntry) {
+ this.portStatsEntry = portStatsEntry;
+ }
- public OFPortStatsEntry getPortStatsEntry() {
- return portStatsEntry;
- }
+ public OFPortStatsEntry getPortStatsEntry() {
+ return portStatsEntry;
+ }
}
-
diff --git a/src/main/java/net/floodlightcontroller/core/web/SwitchResourceBase.java b/src/main/java/net/floodlightcontroller/core/web/SwitchResourceBase.java
index 38b0d1e..5f7b94d 100644
--- a/src/main/java/net/floodlightcontroller/core/web/SwitchResourceBase.java
+++ b/src/main/java/net/floodlightcontroller/core/web/SwitchResourceBase.java
@@ -45,7 +45,7 @@
/**
* Base class for server resources related to switches
- *
+ *
* @author readams
*/
@@ -69,9 +69,8 @@
"from the switch",
recommendation = LogMessageDoc.CHECK_SWITCH + " " +
LogMessageDoc.GENERIC_ACTION)
-
protected List<OFStatsReply> getSwitchStatistics(long switchId,
- OFStatsType statType) {
+ OFStatsType statType) {
IFloodlightProviderService floodlightProvider =
(IFloodlightProviderService) getContext().getAttributes().
get(IFloodlightProviderService.class.getCanonicalName());
@@ -80,18 +79,18 @@
Future<List<OFStatsReply>> future;
List<OFStatsReply> values = null;
if (sw != null) {
- OFStatsRequest<?> req = null;
+ OFStatsRequest<?> req = null;
if (statType == OFStatsType.FLOW) {
- log.debug("Switch Flow Stats req sent for switch {}",
- sw.getStringId());
+ log.debug("Switch Flow Stats req sent for switch {}",
+ sw.getStringId());
OFMatchV3 match = sw.getFactory().buildMatchV3()
- .setOxmList(OFOxmList.EMPTY).build();
- req = sw.getFactory()
- .buildFlowStatsRequest()
- .setMatch(match)
- .setOutPort(OFPort.ANY)
- .setTableId(TableId.ALL)
- .setXid(sw.getNextTransactionId()).build();
+ .setOxmList(OFOxmList.EMPTY).build();
+ req = sw.getFactory()
+ .buildFlowStatsRequest()
+ .setMatch(match)
+ .setOutPort(OFPort.ANY)
+ .setTableId(TableId.ALL)
+ .setXid(sw.getNextTransactionId()).build();
} /*else if (statType == OFStatisticsType.AGGREGATE) {
OFAggregateStatisticsRequest specificReq = new OFAggregateStatisticsRequest();
OFMatch match = new OFMatch();
@@ -101,7 +100,7 @@
specificReq.setTableId((byte) 0xff);
req.setStatistics(Collections.singletonList((OFStatistics) specificReq));
requestLength += specificReq.getLength();
- } /*else if (statType == OFStatisticsType.QUEUE) {
+ } /*else if (statType == OFStatisticsType.QUEUE) {
OFQueueStatisticsRequest specificReq = new OFQueueStatisticsRequest();
specificReq.setPortNumber(OFPort.OFPP_ALL.getValue());
// LOOK! openflowj does not define OFPQ_ALL! pulled this from openflow.h
@@ -109,10 +108,10 @@
specificReq.setQueueId(0xffffffff);
req.setStatistics(Collections.singletonList((OFStatistics) specificReq));
requestLength += specificReq.getLength();
- } else if (statType == OFStatisticsType.DESC ||
+ } else if (statType == OFStatisticsType.DESC ||
statType == OFStatisticsType.TABLE) {
// pass - nothing todo besides set the type above
- }*/
+ }*/
// XXX S fix when we fix stats
try {
future = sw.getStatistics(req);
@@ -125,39 +124,40 @@
}
protected List<OFPortStatsEntryMod> getSwitchPortStatistics(long switchId) {
- IFloodlightProviderService floodlightProvider =
- (IFloodlightProviderService) getContext().getAttributes().
- get(IFloodlightProviderService.class.getCanonicalName());
+ IFloodlightProviderService floodlightProvider =
+ (IFloodlightProviderService) getContext().getAttributes().
+ get(IFloodlightProviderService.class.getCanonicalName());
- IOFSwitch sw = floodlightProvider.getSwitches().get(switchId);
- Future<List<OFStatsReply>> future;
- List<OFStatsReply> values = null;
- List<OFPortStatsEntryMod> portStats = null;
+ IOFSwitch sw = floodlightProvider.getSwitches().get(switchId);
+ Future<List<OFStatsReply>> future;
+ List<OFStatsReply> values = null;
+ List<OFPortStatsEntryMod> portStats = null;
- if (sw != null) {
- log.debug("Switch Port Stats: req sent for all "
- + "ports in switch {}", sw.getStringId());
- OFPortStatsRequest req = sw.getFactory()
- .buildPortStatsRequest()
- .setPortNo(OFPort.ANY).setXid
- (sw.getNextTransactionId()).build();
+ if (sw != null) {
+ log.debug("Switch Port Stats: req sent for all "
+ + "ports in switch {}", sw.getStringId());
+ OFPortStatsRequest req = sw.getFactory()
+ .buildPortStatsRequest()
+ .setPortNo(OFPort.ANY).setXid
+ (sw.getNextTransactionId()).build();
try {
future = sw.getStatistics(req);
values = future.get(10, TimeUnit.SECONDS);
portStats = new ArrayList<OFPortStatsEntryMod>();
- for (OFPortStatsEntry entry : ((OFPortStatsReply)values.get(0)).getEntries()) {
+ for (OFPortStatsEntry entry : ((OFPortStatsReply) values.get(0))
+ .getEntries()) {
OFPortStatsEntryMod entryMod = new OFPortStatsEntryMod(entry);
portStats.add(entryMod);
}
- log.debug("Switch Port Stats Entries from switch {} are {}",
- sw.getStringId(), portStats);
+ log.debug("Switch Port Stats Entries from switch {} are {}",
+ sw.getStringId(), portStats);
} catch (Exception e) {
log.error("Failure retrieving statistics from switch " + sw, e);
}
- }
+ }
- return portStats;
+ return portStats;
}
protected Object getSwitchStatistics(String switchId, OFStatsType statType) {
@@ -170,13 +170,13 @@
get(IFloodlightProviderService.class.getCanonicalName());
IOFSwitch sw = floodlightProvider.getSwitches().get(switchId);
- //uture<OFFeaturesReply> future;
+ // uture<OFFeaturesReply> future;
OFFeaturesReply featuresReply = null;
if (sw != null) {
- // XXX S fix when we fix stats
+ // XXX S fix when we fix stats
try {
- //future = sw.getFeaturesReplyFromSwitch();
- //featuresReply = future.get(10, TimeUnit.SECONDS);
+ // future = sw.getFeaturesReplyFromSwitch();
+ // featuresReply = future.get(10, TimeUnit.SECONDS);
} catch (Exception e) {
log.error("Failure getting features reply from switch" + sw, e);
}
diff --git a/src/main/java/net/floodlightcontroller/core/web/SwitchStatisticsResource.java b/src/main/java/net/floodlightcontroller/core/web/SwitchStatisticsResource.java
index 8c794ab..28be9a4 100644
--- a/src/main/java/net/floodlightcontroller/core/web/SwitchStatisticsResource.java
+++ b/src/main/java/net/floodlightcontroller/core/web/SwitchStatisticsResource.java
@@ -25,10 +25,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
/**
* Return switch statistics information for specific switches
- *
+ *
* @author readams
*/
public class SwitchStatisticsResource extends SwitchResourceBase {
@@ -61,6 +60,6 @@
result.put(switchId, values);
return result;
- //return toRepresentation(result, null);
+ // return toRepresentation(result, null);
}
}
diff --git a/src/main/java/net/floodlightcontroller/core/web/serializers/OFPortStatsEntrySerializer.java b/src/main/java/net/floodlightcontroller/core/web/serializers/OFPortStatsEntrySerializer.java
index c9293f7..cf3062a 100644
--- a/src/main/java/net/floodlightcontroller/core/web/serializers/OFPortStatsEntrySerializer.java
+++ b/src/main/java/net/floodlightcontroller/core/web/serializers/OFPortStatsEntrySerializer.java
@@ -18,9 +18,9 @@
@Override
public void serialize(OFPortStatsEntryMod portStatModEntry, JsonGenerator jGen,
- SerializerProvider sp) throws IOException, JsonGenerationException {
+ SerializerProvider sp) throws IOException, JsonGenerationException {
- OFPortStatsEntry portStatEntry = portStatModEntry.getPortStatsEntry();
+ OFPortStatsEntry portStatEntry = portStatModEntry.getPortStatsEntry();
jGen.writeStartObject();
jGen.writeNumberField("portNumber", portStatEntry.getPortNo().getPortNumber());
jGen.writeNumberField("receivePackets", portStatEntry.getRxPackets().getValue());
@@ -31,8 +31,10 @@
jGen.writeNumberField("transmitDropped", portStatEntry.getTxDropped().getValue());
jGen.writeNumberField("receiveErrors", portStatEntry.getRxErrors().getValue());
jGen.writeNumberField("transmitErrors", portStatEntry.getTxErrors().getValue());
- jGen.writeNumberField("receiveFrameErrors", portStatEntry.getRxFrameErr().getValue());
- jGen.writeNumberField("receiveOverrunErrors", portStatEntry.getRxOverErr().getValue());
+ jGen.writeNumberField("receiveFrameErrors", portStatEntry.getRxFrameErr()
+ .getValue());
+ jGen.writeNumberField("receiveOverrunErrors", portStatEntry.getRxOverErr()
+ .getValue());
jGen.writeNumberField("receiveCRCErrors", portStatEntry.getRxCrcErr().getValue());
jGen.writeNumberField("collisions", portStatEntry.getCollisions().getValue());
diff --git a/src/main/java/net/onrc/onos/apps/segmentrouting/ArpHandler.java b/src/main/java/net/onrc/onos/apps/segmentrouting/ArpHandler.java
index 0a8c316..cb394f8 100644
--- a/src/main/java/net/onrc/onos/apps/segmentrouting/ArpHandler.java
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/ArpHandler.java
@@ -44,9 +44,9 @@
/**
* Handling ARP requests to switches for Segment Routing.
* <p/>
- * The module is for handling ARP requests to switches. It sends ARP response for any known
- * hosts to the controllers.
- * TODO: need to check the network config file for all hosts and packets
+ * The module is for handling ARP requests to switches. It sends ARP response
+ * for any known hosts to the controllers. TODO: need to check the network
+ * config file for all hosts and packets
*/
public class ArpHandler {
@@ -57,7 +57,7 @@
private IFlowPusherService flowPusher;
private ITopologyService topologyService;
private MutableTopology mutableTopology;
- //private List<ArpEntry> arpEntries;
+ // private List<ArpEntry> arpEntries;
private SegmentRoutingManager srManager;
private static final short IDLE_TIMEOUT = 0;
@@ -76,13 +76,14 @@
private static final short SLASH_8_PRIORITY = (short) 0xf000;
private static final short MIN_PRIORITY = 0x0;
-
/*
* Default Constructor
*/
- public ArpHandler(FloodlightModuleContext context, SegmentRoutingManager segmentRoutingManager) {
+ public ArpHandler(FloodlightModuleContext context,
+ SegmentRoutingManager segmentRoutingManager) {
- this.floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class);
+ this.floodlightProvider = context
+ .getServiceImpl(IFloodlightProviderService.class);
this.flowPusher = context.getServiceImpl(IFlowPusherService.class);
this.topologyService = context.getServiceImpl(ITopologyService.class);
this.srManager = segmentRoutingManager;
@@ -93,32 +94,31 @@
}
/**
- * process ARP packets from switches
- * It add a IP routing rule to the host
- * If it is an ARP response, then flush out all pending packets to the host
- *
+ * process ARP packets from switches It add a IP routing rule to the host If
+ * it is an ARP response, then flush out all pending packets to the host
+ *
* @param sw
* @param inPort
* @param payload
*/
- public void processPacketIn(Switch sw, Port inPort, Ethernet payload){
+ public void processPacketIn(Switch sw, Port inPort, Ethernet payload) {
- log.debug("ArpHandler: Received a ARP packet from sw {} ", sw.getDpid());
+ log.debug("ArpHandler: Received a ARP packet from sw {} ", sw.getDpid());
- ARP arp = (ARP)payload.getPayload();
+ ARP arp = (ARP) payload.getPayload();
byte[] senderMacAddressByte = arp.getSenderHardwareAddress();
IPv4Address hostIpAddress = IPv4Address.of(arp.getSenderProtocolAddress());
log.debug("ArpHandler: Add IP route to Host {} ", hostIpAddress);
- srManager.addRouteToHost(sw,hostIpAddress.getInt(), senderMacAddressByte);
+ srManager.addRouteToHost(sw, hostIpAddress.getInt(), senderMacAddressByte);
if (arp.getOpCode() == ARP.OP_REQUEST) {
- log.debug("ArpHandler: Received a ARP Requestfrom sw {} ", sw.getDpid());
+ log.debug("ArpHandler: Received a ARP Requestfrom sw {} ", sw.getDpid());
handleArpRequest(sw, inPort, payload);
}
else {
byte[] destIp = arp.getSenderProtocolAddress();
- for (IPv4 ipPacket: srManager.getIpPacketFromQueue(destIp)) {
+ for (IPv4 ipPacket : srManager.getIpPacketFromQueue(destIp)) {
if (ipPacket != null && !inSameSubnet(sw, ipPacket)) {
Ethernet eth = new Ethernet();
eth.setDestinationMACAddress(payload.getSourceMACAddress());
@@ -133,32 +133,32 @@
/**
* Send an ARP response for the ARP request to the known switches
- *
+ *
* @param sw Switch
* @param inPort port to send ARP response to
* @param arpRequest ARP request packet to handle
*/
private void handleArpRequest(Switch sw, Port inPort, Ethernet payload) {
- ARP arpRequest = (ARP)payload.getPayload();
- MACAddress targetMac = null;
+ ARP arpRequest = (ARP) payload.getPayload();
+ MACAddress targetMac = null;
- if (isArpReqForSwitch(sw, arpRequest)) {
+ if (isArpReqForSwitch(sw, arpRequest)) {
String switchMacAddressStr = sw.getStringAttribute("routerMac");
targetMac = MACAddress.valueOf(switchMacAddressStr);
- log.debug("ArpHandler: Received a ARP query for a sw {} ", sw.getDpid());
- }
- else {
- Host knownHost = isArpReqForKnownHost(sw, arpRequest);
- if (knownHost != null) {
+ log.debug("ArpHandler: Received a ARP query for a sw {} ", sw.getDpid());
+ }
+ else {
+ Host knownHost = isArpReqForKnownHost(sw, arpRequest);
+ if (knownHost != null) {
targetMac = knownHost.getMacAddress();
- log.debug("ArpHandler: Received a ARP query for a known host {} ",
- IPv4Address.of(knownHost.getIpAddress()));
- }
- }
+ log.debug("ArpHandler: Received a ARP query for a known host {} ",
+ IPv4Address.of(knownHost.getIpAddress()));
+ }
+ }
- if (targetMac != null) {
- /* ARP Destination is known. Packet out ARP Reply */
+ if (targetMac != null) {
+ /* ARP Destination is known. Packet out ARP Reply */
ARP arpReply = new ARP();
arpReply.setHardwareType(ARP.HW_TYPE_ETHERNET)
.setProtocolType(ARP.PROTO_TYPE_IP)
@@ -177,53 +177,53 @@
.setEtherType(Ethernet.TYPE_ARP).setPayload(arpReply);
sendPacketOut(sw, eth, inPort.getPortNumber().shortValue());
- }
- else
- {
- /* Broadcast the received ARP request to all switch ports
- * that subnets are connected to except the port from which
- * ARP request is received
- */
- IPv4Address targetAddress =
- IPv4Address.of(arpRequest.getTargetProtocolAddress());
- log.debug("ArpHandler: Received a ARP query for unknown host {} ",
- IPv4Address.of(arpRequest.getTargetProtocolAddress()));
- for (Integer portNo : getSwitchSubnetPorts(sw, targetAddress)) {
- if (portNo.shortValue() == inPort.getPortNumber().shortValue())
- continue;
- log.debug("ArpHandler: Sending ARP request on switch {} port {}",
- sw.getDpid(), portNo.shortValue());
+ }
+ else
+ {
+ /* Broadcast the received ARP request to all switch ports
+ * that subnets are connected to except the port from which
+ * ARP request is received
+ */
+ IPv4Address targetAddress =
+ IPv4Address.of(arpRequest.getTargetProtocolAddress());
+ log.debug("ArpHandler: Received a ARP query for unknown host {} ",
+ IPv4Address.of(arpRequest.getTargetProtocolAddress()));
+ for (Integer portNo : getSwitchSubnetPorts(sw, targetAddress)) {
+ if (portNo.shortValue() == inPort.getPortNumber().shortValue())
+ continue;
+ log.debug("ArpHandler: Sending ARP request on switch {} port {}",
+ sw.getDpid(), portNo.shortValue());
sendPacketOut(sw, payload, portNo.shortValue());
- }
- }
+ }
+ }
}
/**
* Check if the ARP request is to known hosts
- *
- * @param sw Switch
- * @param arpRequest ARP request to check
+ *
+ * @param sw Switch
+ * @param arpRequest ARP request to check
*/
private Host isArpReqForKnownHost(Switch sw, ARP arpRequest) {
- Host knownHost = null;
+ Host knownHost = null;
IPv4Address targetIPAddress = IPv4Address.of(
- arpRequest.getTargetProtocolAddress());
+ arpRequest.getTargetProtocolAddress());
- for (Host host:sw.getHosts()) {
- if (host.getIpAddress() == targetIPAddress.getInt()) {
- knownHost = host;
- break;
- }
+ for (Host host : sw.getHosts()) {
+ if (host.getIpAddress() == targetIPAddress.getInt()) {
+ knownHost = host;
+ break;
+ }
}
return knownHost;
}
/**
- *
+ *
* Check if the ARP is for the switch
- *
+ *
* @param sw Switch
* @param arpRequest ARP request to check
* @return true if the ARP is for the switch
@@ -232,9 +232,10 @@
List<String> subnetGatewayIPs = getSubnetGatewayIps(sw);
boolean isArpForSwitch = false;
if (!subnetGatewayIPs.isEmpty()) {
- IPv4Address targetProtocolAddress = IPv4Address.of(arpRequest.getTargetProtocolAddress());
+ IPv4Address targetProtocolAddress = IPv4Address.of(arpRequest
+ .getTargetProtocolAddress());
if (subnetGatewayIPs.contains(targetProtocolAddress.toString())) {
- isArpForSwitch = true;
+ isArpForSwitch = true;
}
}
return isArpForSwitch;
@@ -242,7 +243,7 @@
/**
* Retrieve Gateway IP address of all subnets defined in net config file
- *
+ *
* @param sw Switch to retrieve subnet GW IPs for
* @return list of GW IP addresses for all subnets
*/
@@ -256,7 +257,8 @@
for (int i = 0; i < arry.length(); i++) {
String subnetIpSlash = (String) arry.getJSONObject(i).get("subnetIp");
if (subnetIpSlash != null) {
- String subnetIp = subnetIpSlash.substring(0, subnetIpSlash.indexOf('/'));
+ String subnetIp = subnetIpSlash.substring(0,
+ subnetIpSlash.indexOf('/'));
gatewayIps.add(subnetIp);
}
}
@@ -277,7 +279,7 @@
for (int i = 0; i < arry.length(); i++) {
String subnetIpSlash = (String) arry.getJSONObject(i).get("subnetIp");
if (srManager.netMatch(subnetIpSlash, targetAddress.toString())) {
- Integer subnetPort = (Integer)arry.getJSONObject(i).get("portNo");
+ Integer subnetPort = (Integer) arry.getJSONObject(i).get("portNo");
switchSubnetPorts.add(subnetPort);
}
}
@@ -291,11 +293,11 @@
/**
* Send an ARP request
- *
+ *
* @param sw Switch
* @param targetAddress Target IP address
* @param inPort Port to send the ARP request
- *
+ *
*/
public void sendArpRequest(Switch sw, int targetAddressInt, Port inPort) {
@@ -326,22 +328,22 @@
.setSourceMACAddress(senderMacAddress)
.setEtherType(Ethernet.TYPE_ARP).setPayload(arpRequest);
- /* Broadcast the ARP request to all switch ports
- * that subnets are connected to except the port from which
- * ARP request is received
- */
- for (Integer portNo : getSwitchSubnetPorts(sw, targetAddress)) {
- if (portNo.shortValue() == inPort.getPortNumber().shortValue())
- continue;
- log.debug("ArpHandler: Sending ARP request on switch {} port {}",
- sw.getDpid(), portNo.shortValue());
+ /* Broadcast the ARP request to all switch ports
+ * that subnets are connected to except the port from which
+ * ARP request is received
+ */
+ for (Integer portNo : getSwitchSubnetPorts(sw, targetAddress)) {
+ if (portNo.shortValue() == inPort.getPortNumber().shortValue())
+ continue;
+ log.debug("ArpHandler: Sending ARP request on switch {} port {}",
+ sw.getDpid(), portNo.shortValue());
sendPacketOut(sw, eth, portNo.shortValue());
- }
+ }
}
/**
* Send PACKET_OUT packet to switch
- *
+ *
* @param sw Switch to send the packet to
* @param packet Packet to send
* @param switchPort port to send (if -1, broadcast)
@@ -363,7 +365,8 @@
Port p = iter.next();
int pnum = p.getPortNumber().shortValue();
if (U32.of(pnum).compareTo(U32.of(OFPort.MAX.getPortNumber())) < 1) {
- OFAction outport = factory.actions().output(OFPort.of(p.getNumber().shortValue()),
+ OFAction outport = factory.actions().output(
+ OFPort.of(p.getNumber().shortValue()),
Short.MAX_VALUE);
actions.add(outport);
}
@@ -380,7 +383,7 @@
/**
* Check if the source IP and destination IP are in the same subnet
- *
+ *
* @param sw Switch
* @param ipv4 IP address to check
* @return return true if the IP packet is within the same subnet
@@ -399,7 +402,7 @@
/**
* Get router IP address for the given IP address
- *
+ *
* @param sourceAddress
* @return
*/
@@ -408,7 +411,7 @@
String gwIp = null;
IPv4Address srcIp = IPv4Address.of(sourceAddress);
- for (Switch sw: mutableTopology.getSwitches()) {
+ for (Switch sw : mutableTopology.getSwitches()) {
String subnets = sw.getStringAttribute("subnets");
try {
@@ -429,4 +432,3 @@
}
}
-
diff --git a/src/main/java/net/onrc/onos/apps/segmentrouting/ECMPShortestPathGraph.java b/src/main/java/net/onrc/onos/apps/segmentrouting/ECMPShortestPathGraph.java
index 0ca2977..0a66cdd 100644
--- a/src/main/java/net/onrc/onos/apps/segmentrouting/ECMPShortestPathGraph.java
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/ECMPShortestPathGraph.java
@@ -49,17 +49,18 @@
switchQueue.add(rootSwitch);
int currDistance = 0;
distanceQueue.add(currDistance);
- switchSearched.put(rootSwitch.getDpid(),currDistance);
+ switchSearched.put(rootSwitch.getDpid(), currDistance);
while (!switchQueue.isEmpty()) {
Switch sw = switchQueue.poll();
Switch prevSw = null;
currDistance = distanceQueue.poll();
for (Link link : sw.getOutgoingLinks()) {
Switch reachedSwitch = link.getDstPort().getSwitch();
- if ((prevSw != null) && (prevSw.getDpid().equals(reachedSwitch.getDpid())))
+ if ((prevSw != null)
+ && (prevSw.getDpid().equals(reachedSwitch.getDpid())))
{
/* Ignore LAG links between the same set of switches */
- continue;
+ continue;
}
else
{
@@ -67,46 +68,47 @@
}
Integer distance = switchSearched.get(reachedSwitch.getDpid());
- if ((distance != null) && (distance.intValue() < (currDistance+1))) {
+ if ((distance != null) && (distance.intValue() < (currDistance + 1))) {
continue;
}
- if (distance == null){
- /* First time visiting this switch node */
+ if (distance == null) {
+ /* First time visiting this switch node */
switchQueue.add(reachedSwitch);
- distanceQueue.add(currDistance+1);
- switchSearched.put(reachedSwitch.getDpid(),currDistance+1);
+ distanceQueue.add(currDistance + 1);
+ switchSearched.put(reachedSwitch.getDpid(), currDistance + 1);
- ArrayList<Switch> distanceSwArray = distanceSwitchMap.get(currDistance+1);
+ ArrayList<Switch> distanceSwArray = distanceSwitchMap
+ .get(currDistance + 1);
if (distanceSwArray == null)
{
- distanceSwArray = new ArrayList<Switch>();
- distanceSwArray.add(reachedSwitch);
- distanceSwitchMap.put(currDistance+1, distanceSwArray);
+ distanceSwArray = new ArrayList<Switch>();
+ distanceSwArray.add(reachedSwitch);
+ distanceSwitchMap.put(currDistance + 1, distanceSwArray);
}
else
- distanceSwArray.add(reachedSwitch);
+ distanceSwArray.add(reachedSwitch);
}
ArrayList<LinkData> upstreamLinkArray =
- upstreamLinks.get(reachedSwitch.getDpid());
+ upstreamLinks.get(reachedSwitch.getDpid());
if (upstreamLinkArray == null)
{
- upstreamLinkArray = new ArrayList<LinkData>();
- upstreamLinkArray.add(new LinkData(link));
- upstreamLinks.put(reachedSwitch.getDpid(), upstreamLinkArray);
+ upstreamLinkArray = new ArrayList<LinkData>();
+ upstreamLinkArray.add(new LinkData(link));
+ upstreamLinks.put(reachedSwitch.getDpid(), upstreamLinkArray);
}
else
- /* ECMP links */
- upstreamLinkArray.add(new LinkData(link));
+ /* ECMP links */
+ upstreamLinkArray.add(new LinkData(link));
}
}
log.debug("ECMPShortestPathGraph:switchSearched for switch {} is {}",
- HexString.toHexString(rootSwitch.getDpid().value()), switchSearched);
+ HexString.toHexString(rootSwitch.getDpid().value()), switchSearched);
log.debug("ECMPShortestPathGraph:upstreamLinks for switch {} is {}",
- HexString.toHexString(rootSwitch.getDpid().value()), upstreamLinks);
+ HexString.toHexString(rootSwitch.getDpid().value()), upstreamLinks);
log.debug("ECMPShortestPathGraph:distanceSwitchMap for switch {} is {}",
- HexString.toHexString(rootSwitch.getDpid().value()), distanceSwitchMap);
+ HexString.toHexString(rootSwitch.getDpid().value()), distanceSwitchMap);
/*
for (Integer distance: distanceSwitchMap.keySet()){
for (Switch sw: distanceSwitchMap.get(distance)){
@@ -122,25 +124,25 @@
private void getDFSPaths(Dpid dstSwitchDpid, Path path, ArrayList<Path> paths) {
Dpid rootSwitchDpid = rootSwitch.getDpid();
for (LinkData upstreamLink : upstreamLinks.get(dstSwitchDpid)) {
- /* Deep clone the path object */
+ /* Deep clone the path object */
Path sofarPath = new Path();
if (!path.isEmpty())
- sofarPath.addAll(path.subList(0, path.size()));
+ sofarPath.addAll(path.subList(0, path.size()));
sofarPath.add(upstreamLink);
if (upstreamLink.getSrc().getDpid().equals(rootSwitchDpid))
{
- paths.add(sofarPath);
- return;
+ paths.add(sofarPath);
+ return;
}
else
- getDFSPaths(upstreamLink.getSrc().getDpid(),sofarPath, paths);
+ getDFSPaths(upstreamLink.getSrc().getDpid(), sofarPath, paths);
}
}
/**
- * Return the computed ECMP paths from the root switch to a given switch
- * in the network
- *
+ * Return the computed ECMP paths from the root switch to a given switch in
+ * the network
+ *
* @param targetSwitch the target switch
* @return the list of ECMP Paths from the root switch to the target switch
*/
@@ -160,19 +162,20 @@
/**
* Return the complete info of the computed ECMP paths for each switch
* learned in multiple iterations from the root switch
- *
+ *
* @return the hash table of Switches learned in multiple Dijkstra
- * iterations and corresponding ECMP paths to it from the root switch
+ * iterations and corresponding ECMP paths to it from the root
+ * switch
*/
public HashMap<Integer, HashMap<Switch,
- ArrayList<Path>>> getCompleteLearnedSwitchesAndPaths() {
+ ArrayList<Path>>> getCompleteLearnedSwitchesAndPaths() {
HashMap<Integer, HashMap<Switch, ArrayList<Path>>> pathGraph = new
- HashMap<Integer, HashMap<Switch, ArrayList<Path>>>();
+ HashMap<Integer, HashMap<Switch, ArrayList<Path>>>();
for (Integer itrIndx : distanceSwitchMap.keySet()) {
HashMap<Switch, ArrayList<Path>> swMap = new
- HashMap<Switch, ArrayList<Path>>();
+ HashMap<Switch, ArrayList<Path>>();
for (Switch sw : distanceSwitchMap.get(itrIndx)) {
swMap.put(sw, getECMPPaths(sw));
}
@@ -184,26 +187,20 @@
/**
* Return the complete info of the computed ECMP paths for each switch
- * learned in multiple iterations from the root switch in the form of
- * {
- * Iteration1,
- * Switch<> via {Switch<>, Switch<>}
- * Switch<> via {Switch<>, Switch<>}
- * Iteration2,
- * Switch<> via {Switch<>, Switch<>, Switch<>}
- * {Switch<>, Switch<>, Switch<>}
- * Switch<> via {Switch<>, Switch<>, Switch<>}
- * }
- *
+ * learned in multiple iterations from the root switch in the form of {
+ * Iteration1, Switch<> via {Switch<>, Switch<>} Switch<> via {Switch<>,
+ * Switch<>} Iteration2, Switch<> via {Switch<>, Switch<>, Switch<>}
+ * {Switch<>, Switch<>, Switch<>} Switch<> via {Switch<>, Switch<>,
+ * Switch<>} }
+ *
* @return the hash table of Switches learned in multiple Dijkstra
- * iterations and corresponding ECMP paths in terms of Switches to be
- * traversed to it from the root switch
+ * iterations and corresponding ECMP paths in terms of Switches to
+ * be traversed to it from the root switch
*/
public HashMap<Integer, HashMap<Switch,
- ArrayList<ArrayList<Dpid>>>> getAllLearnedSwitchesAndVia() {
+ ArrayList<ArrayList<Dpid>>>> getAllLearnedSwitchesAndVia() {
- HashMap<Integer, HashMap<Switch, ArrayList<ArrayList<Dpid>>>>
- switchViaMap = new HashMap<Integer, HashMap<Switch, ArrayList<ArrayList<Dpid>>>>();
+ HashMap<Integer, HashMap<Switch, ArrayList<ArrayList<Dpid>>>> switchViaMap = new HashMap<Integer, HashMap<Switch, ArrayList<ArrayList<Dpid>>>>();
for (Integer itrIndx : distanceSwitchMap.keySet()) {
HashMap<Switch, ArrayList<ArrayList<Dpid>>> swMap =
@@ -211,10 +208,10 @@
for (Switch sw : distanceSwitchMap.get(itrIndx)) {
ArrayList<ArrayList<Dpid>> swViaArray = new ArrayList<>();
- for (Path path:getECMPPaths(sw)){
+ for (Path path : getECMPPaths(sw)) {
ArrayList<Dpid> swVia = new ArrayList<>();
- for (LinkData link:path.subList(0, path.size())){
- if (link.getSrc().getDpid().equals(rootSwitch.getDpid())){
+ for (LinkData link : path.subList(0, path.size())) {
+ if (link.getSrc().getDpid().equals(rootSwitch.getDpid())) {
/* No need to add the root switch again in
* the Via list
*/
diff --git a/src/main/java/net/onrc/onos/apps/segmentrouting/GenericIpHandler.java b/src/main/java/net/onrc/onos/apps/segmentrouting/GenericIpHandler.java
index fd27e56..edd2539 100644
--- a/src/main/java/net/onrc/onos/apps/segmentrouting/GenericIpHandler.java
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/GenericIpHandler.java
@@ -59,7 +59,8 @@
private static final short MIN_PRIORITY = 0x0;
public GenericIpHandler(FloodlightModuleContext context, SegmentRoutingManager sr) {
- this.floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class);
+ this.floodlightProvider = context
+ .getServiceImpl(IFloodlightProviderService.class);
this.topologyService = context.getServiceImpl(ITopologyService.class);
this.mutableTopology = topologyService.getTopology();
this.flowPusher = context.getServiceImpl(IFlowPusherService.class);
@@ -71,11 +72,11 @@
// TODO Auto-generated method stub
log.debug("GenericIPHandler: Received a IP packet {} from sw {} ",
payload.toString(), sw.getDpid());
- IPv4 ipv4 = (IPv4)payload.getPayload();
+ IPv4 ipv4 = (IPv4) payload.getPayload();
int destinationAddress = ipv4.getDestinationAddress();
// Check if the destination is any host known to TopologyService
- for (net.onrc.onos.core.topology.Host host: mutableTopology.getHosts()) {
+ for (net.onrc.onos.core.topology.Host host : mutableTopology.getHosts()) {
IPv4Address hostIpAddress = IPv4Address.of(host.getIpAddress());
if (hostIpAddress != null && hostIpAddress.getInt() == destinationAddress) {
byte[] destinationMacAddress = host.getMacAddress().toBytes();
@@ -96,17 +97,18 @@
return true;
}
-
/**
* Add routing rules to forward packets to known hosts
- *
+ *
* @param sw Switch
* @param hostIp Host IP address to forwards packets to
*/
- public void addRouteToHost(Switch sw, int destinationAddress, byte[] destinationMacAddress) {
+ public void addRouteToHost(Switch sw, int destinationAddress,
+ byte[] destinationMacAddress) {
// If we do not know the host, then we cannot set the forwarding rule
- net.onrc.onos.core.topology.Host host = mutableTopology.getHostByMac(MACAddress.valueOf(destinationMacAddress));
+ net.onrc.onos.core.topology.Host host = mutableTopology.getHostByMac(MACAddress
+ .valueOf(destinationMacAddress));
if (host == null) {
return;
}
@@ -114,7 +116,6 @@
IOFSwitch ofSwitch = floodlightProvider.getMasterSwitch(sw.getDpid().value());
OFFactory factory = ofSwitch.getFactory();
-
OFOxmEthType ethTypeIp = factory.oxms()
.ethType(EthType.IPv4);
OFOxmIpv4DstMasked ipPrefix = factory.oxms()
@@ -143,7 +144,6 @@
actionList.add(decTtl);
actionList.add(setSA);
-
/* TODO : need to check the config file for all packets
String subnets = sw.getStringAttribute("subnets");
try {
@@ -165,7 +165,7 @@
*/
// Set output port
- for (Port port: host.getAttachmentPoints()) {
+ for (Port port : host.getAttachmentPoints()) {
OFAction out = factory.actions().buildOutput()
.setPort(OFPort.of(port.getPortNumber().shortValue())).build();
actionList.add(out);
@@ -185,14 +185,14 @@
.setBufferId(OFBufferId.NO_BUFFER)
.setIdleTimeout(0)
.setHardTimeout(0)
- //.setXid(getNextTransactionId())
+ // .setXid(getNextTransactionId())
.build();
- log.debug("Sending 'Routing information' OF message to the switch {}.", sw.getDpid().toString());
+ log.debug("Sending 'Routing information' OF message to the switch {}.", sw
+ .getDpid().toString());
flowPusher.add(sw.getDpid(), myIpEntry);
}
-
}
diff --git a/src/main/java/net/onrc/onos/apps/segmentrouting/IcmpHandler.java b/src/main/java/net/onrc/onos/apps/segmentrouting/IcmpHandler.java
index 3b65d55..778658a 100644
--- a/src/main/java/net/onrc/onos/apps/segmentrouting/IcmpHandler.java
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/IcmpHandler.java
@@ -1,4 +1,3 @@
-
/*******************************************************************************
* Copyright (c) 2014 Open Networking Laboratory.
* All rights reserved. This program and the accompanying materials
@@ -80,10 +79,10 @@
private static final int ICMP_TYPE_ECHO = 0x08;
private static final int ICMP_TYPE_REPLY = 0x00;
-
public IcmpHandler(FloodlightModuleContext context, SegmentRoutingManager manager) {
- this.floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class);
+ this.floodlightProvider = context
+ .getServiceImpl(IFloodlightProviderService.class);
this.flowPusher = context.getServiceImpl(IFlowPusherService.class);
this.topologyService = context.getServiceImpl(ITopologyService.class);
this.mutableTopology = topologyService.getTopology();
@@ -92,13 +91,12 @@
}
/**
- * handle ICMP packets
- * If it is for ICMP echo to router IP or any subnet GW IP,
- * then send ICMP response on behalf of the switch.
- * If it is for any hosts in subnets of the switches, but if the MAC
- * address is not known, then send an ARP request to the subent.
- * If the MAC address is known, then set the routing rule to the switch
- *
+ * handle ICMP packets If it is for ICMP echo to router IP or any subnet GW
+ * IP, then send ICMP response on behalf of the switch. If it is for any
+ * hosts in subnets of the switches, but if the MAC address is not known,
+ * then send an ARP request to the subent. If the MAC address is known, then
+ * set the routing rule to the switch
+ *
* @param sw
* @param inPort
* @param payload
@@ -107,7 +105,7 @@
if (payload.getEtherType() == Ethernet.TYPE_IPV4) {
- IPv4 ipv4 = (IPv4)payload.getPayload();
+ IPv4 ipv4 = (IPv4) payload.getPayload();
if (ipv4.getProtocol() == IPv4.PROTOCOL_ICMP) {
@@ -119,13 +117,13 @@
// Check if it is ICMP request to the switch
String switchIpAddressSlash = sw.getStringAttribute("routerIp");
if (switchIpAddressSlash != null) {
- String switchIpAddressStr
- = switchIpAddressSlash.substring(0, switchIpAddressSlash.indexOf('/'));
+ String switchIpAddressStr = switchIpAddressSlash.substring(0,
+ switchIpAddressSlash.indexOf('/'));
IPv4Address switchIpAddress = IPv4Address.of(switchIpAddressStr);
List<String> gatewayIps = getSubnetGatewayIps(sw);
- if (((ICMP)ipv4.getPayload()).getIcmpType() == ICMP_TYPE_ECHO &&
+ if (((ICMP) ipv4.getPayload()).getIcmpType() == ICMP_TYPE_ECHO &&
(destinationAddress.getInt() == switchIpAddress.getInt() ||
- gatewayIps.contains(destinationAddress.toString()))) {
+ gatewayIps.contains(destinationAddress.toString()))) {
log.debug("ICMPHandler: ICMP packet for sw {} and "
+ "sending ICMP response ", sw.getDpid());
sendICMPResponse(sw, inPort, payload);
@@ -135,7 +133,7 @@
}
/* Check if ICMP is for any switch known host */
- for (Host host: sw.getHosts()) {
+ for (Host host : sw.getHosts()) {
IPv4Address hostIpAddress =
IPv4Address.of(host.getIpAddress());
if (hostIpAddress != null &&
@@ -149,17 +147,19 @@
* again just in case and flush any pending packets to the host.
*/
log.debug("ICMPHandler: ICMP request for known host {}",
- hostIpAddress);
+ hostIpAddress);
byte[] destinationMacAddress = host.getMacAddress().toBytes();
srManager.addRouteToHost(sw,
destinationAddress.getInt(), destinationMacAddress);
byte[] destIp = destinationAddress.getBytes();
- for (IPv4 ipPacket: srManager.getIpPacketFromQueue(destIp)) {
+ for (IPv4 ipPacket : srManager.getIpPacketFromQueue(destIp)) {
if (ipPacket != null && !inSameSubnet(sw, ipPacket)) {
Ethernet eth = new Ethernet();
- eth.setDestinationMACAddress(payload.getSourceMACAddress());
- eth.setSourceMACAddress(sw.getStringAttribute("routerMac"));
+ eth.setDestinationMACAddress(payload
+ .getSourceMACAddress());
+ eth.setSourceMACAddress(sw
+ .getStringAttribute("routerMac"));
eth.setEtherType(Ethernet.TYPE_IPV4);
eth.setPayload(ipPacket);
sendPacketOut(sw, eth, inPort.getSwitchPort(), false);
@@ -178,11 +178,9 @@
}
}
-
-
/**
* Retrieve Gateway IP address of all subnets defined in net config file
- *
+ *
* @param sw Switch to retrieve subnet GW IPs for
* @return list of GW IP addresses for all subnets
*/
@@ -196,7 +194,8 @@
for (int i = 0; i < arry.length(); i++) {
String subnetIpSlash = (String) arry.getJSONObject(i).get("subnetIp");
if (subnetIpSlash != null) {
- String subnetIp = subnetIpSlash.substring(0, subnetIpSlash.indexOf('/'));
+ String subnetIp = subnetIpSlash.substring(0,
+ subnetIpSlash.indexOf('/'));
gatewayIps.add(subnetIp);
}
}
@@ -208,10 +207,9 @@
return gatewayIps;
}
-
/**
* Send ICMP reply back
- *
+ *
* @param sw Switch
* @param inPort Port the ICMP packet is forwarded from
* @param icmpRequest the ICMP request to handle
@@ -226,14 +224,13 @@
int destAddress = icmpRequestIpv4.getDestinationAddress();
icmpReplyIpv4.setDestinationAddress(icmpRequestIpv4.getSourceAddress());
icmpReplyIpv4.setSourceAddress(destAddress);
- icmpReplyIpv4.setTtl((byte)64);
- icmpReplyIpv4.setChecksum((short)0);
+ icmpReplyIpv4.setTtl((byte) 64);
+ icmpReplyIpv4.setChecksum((short) 0);
-
- ICMP icmpReply = (ICMP)icmpRequestIpv4.getPayload().clone();
- icmpReply.setIcmpCode((byte)0x00);
+ ICMP icmpReply = (ICMP) icmpRequestIpv4.getPayload().clone();
+ icmpReply.setIcmpCode((byte) 0x00);
icmpReply.setIcmpType((byte) ICMP_TYPE_REPLY);
- icmpReply.setChecksum((short)0);
+ icmpReply.setChecksum((short) 0);
icmpReplyIpv4.setPayload(icmpReply);
@@ -242,23 +239,25 @@
icmpReplyEth.setDestinationMACAddress(icmpRequest.getSourceMACAddress());
icmpReplyEth.setSourceMACAddress(icmpRequest.getDestinationMACAddress());
- sendPacketOut(sw, icmpReplyEth, new SwitchPort(sw.getDpid(), inPort.getPortNumber()), false);
+ sendPacketOut(sw, icmpReplyEth,
+ new SwitchPort(sw.getDpid(), inPort.getPortNumber()), false);
log.debug("Send an ICMP response {}", icmpReplyIpv4.toString());
}
/**
- * Send PACKET_OUT message with actions
- * If switches support OFPP_TABLE action, it sends out packet to TABLE port
- * Otherwise, it sends the packet to the port the packet came from
- * (in this case, MPLS label is added if the packet needs go through transit switches)
- *
- * @param sw Switch the packet came from
+ * Send PACKET_OUT message with actions If switches support OFPP_TABLE
+ * action, it sends out packet to TABLE port Otherwise, it sends the packet
+ * to the port the packet came from (in this case, MPLS label is added if
+ * the packet needs go through transit switches)
+ *
+ * @param sw Switch the packet came from
* @param packet Ethernet packet to send
* @param switchPort port to send the packet
*/
- private void sendPacketOut(Switch sw, Ethernet packet, SwitchPort switchPort, boolean supportOfppTable) {
+ private void sendPacketOut(Switch sw, Ethernet packet, SwitchPort switchPort,
+ boolean supportOfppTable) {
boolean sameSubnet = false;
IOFSwitch ofSwitch = floodlightProvider.getMasterSwitch(sw.getDpid().value());
@@ -266,12 +265,14 @@
List<OFAction> actions = new ArrayList<>();
- // If OFPP_TABLE action is not supported in the switch, MPLS label needs to be set
+ // If OFPP_TABLE action is not supported in the switch, MPLS label needs
+ // to be set
// if the packet needs to be delivered crossing switches
if (!supportOfppTable) {
// Check if the destination is the host attached to the switch
- int destinationAddress = ((IPv4)packet.getPayload()).getDestinationAddress();
- for (net.onrc.onos.core.topology.Host host: mutableTopology.getHosts(switchPort)) {
+ int destinationAddress = ((IPv4) packet.getPayload()).getDestinationAddress();
+ for (net.onrc.onos.core.topology.Host host : mutableTopology
+ .getHosts(switchPort)) {
IPv4Address hostIpAddress = IPv4Address.of(host.getIpAddress());
if (hostIpAddress != null && hostIpAddress.getInt() == destinationAddress) {
sameSubnet = true;
@@ -279,10 +280,12 @@
}
}
- IPv4Address targetAddress = IPv4Address.of(((IPv4)packet.getPayload()).getDestinationAddress());
+ IPv4Address targetAddress = IPv4Address.of(((IPv4) packet.getPayload())
+ .getDestinationAddress());
String destMacAddress = packet.getDestinationMAC().toString();
// If the destination host is not attached in the switch
- // and the destination is not the neighbor switch, then add MPLS label
+ // and the destination is not the neighbor switch, then add MPLS
+ // label
String targetMac = getRouterMACFromConfig(targetAddress);
if (!sameSubnet && !targetMac.equals(destMacAddress)) {
int mplsLabel = getMplsLabelFromConfig(targetAddress);
@@ -299,10 +302,12 @@
}
}
- OFAction outport = factory.actions().output(OFPort.of(switchPort.getPortNumber().shortValue()), Short.MAX_VALUE);
+ OFAction outport = factory.actions().output(
+ OFPort.of(switchPort.getPortNumber().shortValue()), Short.MAX_VALUE);
actions.add(outport);
}
- // If OFPP_TABLE action is supported, first set a rule to allow packet from CONTROLLER port.
+ // If OFPP_TABLE action is supported, first set a rule to allow packet
+ // from CONTROLLER port.
// Then, send the packet to the table port
else {
if (!controllerPortAllowed) {
@@ -323,7 +328,7 @@
/**
* Get MPLS label for the target address from the network config file
- *
+ *
* @param targetAddress - IP address of the target host
* @return MPLS label of the switch to send packets to the target address
*/
@@ -331,7 +336,7 @@
int mplsLabel = -1;
- for (Switch sw: mutableTopology.getSwitches()) {
+ for (Switch sw : mutableTopology.getSwitches()) {
String subnets = sw.getStringAttribute("subnets");
try {
@@ -353,10 +358,10 @@
return mplsLabel;
}
-
/**
- * Get Router MAC Address for the target address from the network config file
- *
+ * Get Router MAC Address for the target address from the network config
+ * file
+ *
* @param targetAddress - IP address of the target host
* @return Router MAC of the switch to send packets to the target address
*/
@@ -364,7 +369,7 @@
String routerMac = null;
- for (Switch sw: mutableTopology.getSwitches()) {
+ for (Switch sw : mutableTopology.getSwitches()) {
String subnets = sw.getStringAttribute("subnets");
try {
@@ -372,7 +377,7 @@
for (int i = 0; i < arry.length(); i++) {
String subnetIp = (String) arry.getJSONObject(i).get("subnetIp");
if (srManager.netMatch(subnetIp, targetAddress.toString())) {
- routerMac = sw.getStringAttribute("routerMac");
+ routerMac = sw.getStringAttribute("routerMac");
}
}
} catch (JSONException e) {
@@ -385,10 +390,10 @@
}
/**
- * Add a new rule to VLAN table to forward packets from any port to the next table
- * It is required to forward packets from controller to pipeline
- *
- * @param sw Switch the packet came from
+ * Add a new rule to VLAN table to forward packets from any port to the next
+ * table It is required to forward packets from controller to pipeline
+ *
+ * @param sw Switch the packet came from
*/
private void addControlPortInVlanTable(Switch sw) {
@@ -401,7 +406,7 @@
OFOxmList oxmList = OFOxmList.of(oxv);
/* Cqpd switch does not seems to support CONTROLLER port as in_port match rule */
- //OFOxmList oxmList = OFOxmList.of(oxp, oxv);
+ // OFOxmList oxmList = OFOxmList.of(oxp, oxv);
OFMatchV3 match = factory.buildMatchV3()
.setOxmList(oxmList)
@@ -420,17 +425,17 @@
.setBufferId(OFBufferId.NO_BUFFER)
.setIdleTimeout(0)
.setHardTimeout(0)
- //.setXid(getNextTransactionId())
+ // .setXid(getNextTransactionId())
.build();
- flowPusher.add(sw.getDpid(), flowEntry);;
+ flowPusher.add(sw.getDpid(), flowEntry);
log.debug("Adding a new vlan-rules in sw {}", sw.getDpid());
}
/**
* Check if the source IP and destination IP are in the same subnet
- *
+ *
* @param sw Switch
* @param ipv4 IP address to check
* @return return true if the IP packet is within the same subnet
@@ -449,7 +454,7 @@
/**
* Get router IP address for the given IP address
- *
+ *
* @param sourceAddress
* @return
*/
@@ -458,7 +463,7 @@
String gwIp = null;
IPv4Address srcIp = IPv4Address.of(sourceAddress);
- for (Switch sw: mutableTopology.getSwitches()) {
+ for (Switch sw : mutableTopology.getSwitches()) {
String subnets = sw.getStringAttribute("subnets");
try {
diff --git a/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingManager.java b/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingManager.java
index 89ce633..a8f4f1c 100644
--- a/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingManager.java
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingManager.java
@@ -69,7 +69,7 @@
import org.slf4j.LoggerFactory;
public class SegmentRoutingManager implements IFloodlightModule,
- ITopologyListener, IPacketListener {
+ ITopologyListener, IPacketListener {
private static final Logger log = LoggerFactory
.getLogger(SegmentRoutingManager.class);
@@ -145,36 +145,38 @@
@Override
public void receive(Switch sw, Port inPort, Ethernet payload) {
- if (payload.getEtherType() == Ethernet.TYPE_ARP)
- arpHandler.processPacketIn(sw, inPort, payload);
+ if (payload.getEtherType() == Ethernet.TYPE_ARP)
+ arpHandler.processPacketIn(sw, inPort, payload);
if (payload.getEtherType() == Ethernet.TYPE_IPV4) {
- addPacket((IPv4)payload.getPayload());
- if (((IPv4)payload.getPayload()).getProtocol() == IPv4.PROTOCOL_ICMP)
- icmpHandler.processPacketIn(sw, inPort, payload);
- else
- ipHandler.processPacketIn(sw, inPort, payload);
+ addPacket((IPv4) payload.getPayload());
+ if (((IPv4) payload.getPayload()).getProtocol() == IPv4.PROTOCOL_ICMP)
+ icmpHandler.processPacketIn(sw, inPort, payload);
+ else
+ ipHandler.processPacketIn(sw, inPort, payload);
}
else {
log.debug("{}", payload.toString());
}
}
+
/**
- * Update ARP Cache using ARP packets
- * It is used to set destination MAC address to forward packets to known hosts.
- * But, it will be replace with Host information of Topology service later.
- *
+ * Update ARP Cache using ARP packets It is used to set destination MAC
+ * address to forward packets to known hosts. But, it will be replace with
+ * Host information of Topology service later.
+ *
* @param arp APR packets to use for updating ARP entries
*/
public void updateArpCache(ARP arp) {
- ArpEntry arpEntry = new ArpEntry(arp.getSenderHardwareAddress(), arp.getSenderProtocolAddress());
+ ArpEntry arpEntry = new ArpEntry(arp.getSenderHardwareAddress(),
+ arp.getSenderProtocolAddress());
// TODO: Need to check the duplication
arpEntries.add(arpEntry);
}
/**
* Get MAC address to known hosts
- *
+ *
* @param destinationAddress IP address to get MAC address
* @return MAC Address to given IP address
*/
@@ -187,14 +189,14 @@
IPv4Address ipAddress = IPv4Address.of(destinationAddress);
byte[] ipAddressInByte = ipAddress.getBytes();
- while (iterator.hasNext() ) {
+ while (iterator.hasNext()) {
ArpEntry arpEntry = iterator.next();
byte[] address = arpEntry.targetIpAddress;
IPv4Address a = IPv4Address.of(address);
IPv4Address b = IPv4Address.of(ipAddressInByte);
- if ( a.equals(b)) {
+ if (a.equals(b)) {
log.debug("Found an arp entry");
return arpEntry.targetMacAddress;
}
@@ -205,10 +207,11 @@
/**
* Send an ARP request via ArpHandler
+ *
* @param destinationAddress
* @param sw
* @param inPort
- *
+ *
*/
public void sendArpRequest(Switch sw, int destinationAddress, Port inPort) {
arpHandler.sendArpRequest(sw, destinationAddress, inPort);
@@ -216,7 +219,7 @@
/**
* Temporary class to to keep ARP entry
- *
+ *
*/
private class ArpEntry {
@@ -231,7 +234,7 @@
/**
* Topology events that have been generated.
- *
+ *
* @param topologyEvents the generated Topology Events
* @see TopologyEvents
*/
@@ -265,25 +268,25 @@
/**
* Report ports newly added to driver
- *
+ *
* @param portEntries
*/
private void processPortAdd(Collection<PortData> portEntries) {
- //TODO: do we need to add ports slowly?
- for (PortData port: portEntries) {
+ // TODO: do we need to add ports slowly?
+ for (PortData port : portEntries) {
Dpid dpid = port.getDpid();
int portNo = (int) port.getPortNumber().value();
- IOF13Switch sw13 = (IOF13Switch)floodlightProvider.getMasterSwitch(
+ IOF13Switch sw13 = (IOF13Switch) floodlightProvider.getMasterSwitch(
getSwId(port.getDpid().toString()));
- //sw13.addPort(portNo);
+ // sw13.addPort(portNo);
log.debug("Add port {} to switch {}", portNo, dpid.toString());
}
}
/**
* Reports ports of new links to driver and recalculate ECMP SPG
- *
+ *
* @param linkEntries
*/
private void processLinkAdd(Collection<LinkData> linkEntries) {
@@ -291,44 +294,44 @@
// TODO: How to determine this link was broken before and back now
// If so, we need to ad the link slowly...
// Or, just add any new or restored link slowly ???
- for (LinkData link: linkEntries) {
+ for (LinkData link : linkEntries) {
SwitchPort srcPort = link.getSrc();
SwitchPort dstPort = link.getDst();
- IOF13Switch sw13src = (IOF13Switch)floodlightProvider.getMasterSwitch(
+ IOF13Switch sw13src = (IOF13Switch) floodlightProvider.getMasterSwitch(
getSwId(srcPort.getDpid().toString()));
- IOF13Switch sw13dst = (IOF13Switch)floodlightProvider.getMasterSwitch(
+ IOF13Switch sw13dst = (IOF13Switch) floodlightProvider.getMasterSwitch(
getSwId(srcPort.getDpid().toString()));
- //sw13src.addPort(srcPort);
- //sw13dst.addPort(dstPort);
+ // sw13src.addPort(srcPort);
+ // sw13dst.addPort(dstPort);
}
discoveryTask.reschedule(1, TimeUnit.SECONDS);
}
/**
- * Check if all links are gone b/w the two switches.
- * If all links are gone, then we need to recalculate the path.
- * Otherwise, just report link failure to the driver.
- *
+ * Check if all links are gone b/w the two switches. If all links are gone,
+ * then we need to recalculate the path. Otherwise, just report link failure
+ * to the driver.
+ *
* @param linkEntries
*/
private void processLinkRemoval(Collection<LinkData> linkEntries) {
- for (LinkData link: linkEntries) {
+ for (LinkData link : linkEntries) {
SwitchPort srcPort = link.getSrc();
SwitchPort dstPort = link.getDst();
- IOF13Switch sw13src = (IOF13Switch)floodlightProvider.getMasterSwitch(
+ IOF13Switch sw13src = (IOF13Switch) floodlightProvider.getMasterSwitch(
getSwId(srcPort.getDpid().toString()));
- IOF13Switch sw13dst = (IOF13Switch)floodlightProvider.getMasterSwitch(
+ IOF13Switch sw13dst = (IOF13Switch) floodlightProvider.getMasterSwitch(
getSwId(srcPort.getDpid().toString()));
- //sw13src.addPort(srcPort);
- //sw13dst.addPort(dstPort);
+ // sw13src.addPort(srcPort);
+ // sw13dst.addPort(dstPort);
Switch srcSwitch = mutableTopology.getSwitch(srcPort.getDpid());
if (srcSwitch.getLinkToNeighbor(dstPort.getDpid()) == null) {
discoveryTask.reschedule(1, TimeUnit.SECONDS);
- log.debug("All links are gone b/w {} and {}",srcPort.getDpid(),
+ log.debug("All links are gone b/w {} and {}", srcPort.getDpid(),
srcPort.getDpid());
}
}
@@ -336,51 +339,51 @@
/**
* report ports removed to the driver immediately
- *
+ *
* @param portEntries
*/
private void processPortRemoval(Collection<PortData> portEntries) {
- for (PortData port: portEntries) {
+ for (PortData port : portEntries) {
Dpid dpid = port.getDpid();
int portNo = (int) port.getPortNumber().value();
- IOF13Switch sw13 = (IOF13Switch)floodlightProvider.getMasterSwitch(
+ IOF13Switch sw13 = (IOF13Switch) floodlightProvider.getMasterSwitch(
getSwId(port.getDpid().toString()));
- //sw13.removePort(portNo);
+ // sw13.removePort(portNo);
log.debug("Remove port {} from switch {}", portNo, dpid.toString());
}
}
/**
* Populate routing rules walking through the ECMP shortest paths
- *
+ *
*/
private void populateEcmpRoutingRules() {
- Iterable<Switch> switches= mutableTopology.getSwitches();
+ Iterable<Switch> switches = mutableTopology.getSwitches();
for (Switch sw : switches) {
ECMPShortestPathGraph ecmpSPG = new ECMPShortestPathGraph(sw);
log.debug("ECMPShortestPathGraph is computed for switch {}",
HexString.toHexString(sw.getDpid().value()));
- HashMap<Integer, HashMap<Switch,ArrayList<ArrayList<Dpid>>>> switchVia =
+ HashMap<Integer, HashMap<Switch, ArrayList<ArrayList<Dpid>>>> switchVia =
ecmpSPG.getAllLearnedSwitchesAndVia();
- for (Integer itrIdx: switchVia.keySet()){
+ for (Integer itrIdx : switchVia.keySet()) {
log.debug("ECMPShortestPathGraph:Switches learned in "
+ "Iteration{} from switch {}:",
itrIdx,
HexString.toHexString(sw.getDpid().value()));
HashMap<Switch, ArrayList<ArrayList<Dpid>>> swViaMap =
- switchVia.get(itrIdx);
- for (Switch targetSw: swViaMap.keySet()){
+ switchVia.get(itrIdx);
+ for (Switch targetSw : swViaMap.keySet()) {
log.debug("ECMPShortestPathGraph:****switch {} via:",
HexString.toHexString(targetSw.getDpid().value()));
String destSw = sw.getDpid().toString();
List<String> fwdToSw = new ArrayList<String>();
- int i=0;
- for (ArrayList<Dpid> via:swViaMap.get(targetSw)){
- log.debug("ECMPShortestPathGraph:******{}) {}",++i,via);
+ int i = 0;
+ for (ArrayList<Dpid> via : swViaMap.get(targetSw)) {
+ log.debug("ECMPShortestPathGraph:******{}) {}", ++i, via);
if (via.isEmpty()) {
fwdToSw.add(destSw);
}
@@ -393,15 +396,14 @@
// Send Barrier Message and make sure all rules are set
// before we set the rules to next routers
- IOF13Switch sw13 = (IOF13Switch)floodlightProvider.getMasterSwitch(
+ IOF13Switch sw13 = (IOF13Switch) floodlightProvider.getMasterSwitch(
getSwId(sw.getDpid().toString()));
try {
OFBarrierReplyFuture replyFuture = sw13.sendBarrier();
replyFuture.get(10, TimeUnit.SECONDS);
} catch (IOException e) {
e.printStackTrace();
- }
- catch (InterruptedException | ExecutionException | TimeoutException e) {
+ } catch (InterruptedException | ExecutionException | TimeoutException e) {
log.error("Barrier message not received for sw: {}", sw.getDpid());
e.printStackTrace();
}
@@ -410,22 +412,21 @@
}
/**
- *
- * Set routing rules in targetSw
- * {forward packets to fwdToSw switches in order to send packets to destSw}
- * - If the target switch is an edge router and final destnation switch is also
- * an edge router, then set IP forwarding rules to subnets
- * - If only the target switch is an edge router, then set IP forwarding rule to
- * the transit router loopback IP address
- * - If the target is a transit router, then just set the MPLS forwarding rule
- *
+ *
+ * Set routing rules in targetSw {forward packets to fwdToSw switches in
+ * order to send packets to destSw} - If the target switch is an edge router
+ * and final destnation switch is also an edge router, then set IP
+ * forwarding rules to subnets - If only the target switch is an edge
+ * router, then set IP forwarding rule to the transit router loopback IP
+ * address - If the target is a transit router, then just set the MPLS
+ * forwarding rule
+ *
* @param targetSw Switch to set the rules
- * @param destSw Final destination switches
+ * @param destSw Final destination switches
* @param fwdToSw next hop switches
*/
private void setRoutingRule(Switch targetSw, String destSw, List<String> fwdToSw) {
-
if (fwdToSw.isEmpty()) {
fwdToSw.add(destSw);
}
@@ -433,18 +434,20 @@
// if both target SW and dest SW are an edge router, then set IP table
if (IsEdgeRouter(targetSw.getDpid().toString()) &&
IsEdgeRouter(destSw)) {
- // We assume that there is at least one transit router b/w edge routers
+ // We assume that there is at least one transit router b/w edge
+ // routers
Switch destSwitch = mutableTopology.getSwitch(new Dpid(destSw));
String subnets = destSwitch.getStringAttribute("subnets");
setIpTableRouterSubnet(targetSw, subnets, getMplsLabel(destSw)
- ,fwdToSw);
+ , fwdToSw);
String routerIp = destSwitch.getStringAttribute("routerIp");
setIpTableRouter(targetSw, routerIp, getMplsLabel(destSw), fwdToSw, null);
}
// Only if the target switch is the edge router, then set the IP rules
else if (IsEdgeRouter(targetSw.getDpid().toString())) {
- // We assume that there is at least one transit router b/w edge routers
+ // We assume that there is at least one transit router b/w edge
+ // routers
Switch destSwitch = mutableTopology.getSwitch(new Dpid(destSw));
String routerIp = destSwitch.getStringAttribute("routerIp");
setIpTableRouter(targetSw, routerIp, getMplsLabel(destSw), fwdToSw, null);
@@ -459,7 +462,7 @@
private void setIpTableRouterSubnet(Switch targetSw, String subnets,
String mplsLabel, List<String> fwdToSw) {
- Collection <MatchActionOperationEntry> entries =
+ Collection<MatchActionOperationEntry> entries =
new ArrayList<MatchActionOperationEntry>();
try {
@@ -473,7 +476,7 @@
}
if (!entries.isEmpty()) {
- IOF13Switch sw13 = (IOF13Switch)floodlightProvider.getMasterSwitch(
+ IOF13Switch sw13 = (IOF13Switch) floodlightProvider.getMasterSwitch(
getSwId(targetSw.getDpid().toString()));
try {
@@ -486,16 +489,15 @@
}
/**
- * Check if the switch is the edge router or not
- * If any subnet information is defined in the config file, the we assume
- * it is an edge router
- *
- * @param dpid Dpid of the switch to check
+ * Check if the switch is the edge router or not If any subnet information
+ * is defined in the config file, the we assume it is an edge router
+ *
+ * @param dpid Dpid of the switch to check
* @return true if it is an edge router, otherwise false
*/
private boolean IsEdgeRouter(String dpid) {
- for (Switch sw: mutableTopology.getSwitches()) {
+ for (Switch sw : mutableTopology.getSwitches()) {
String dpidStr = sw.getDpid().toString();
if (dpid.equals(dpidStr)) {
String subnetInfo = sw.getStringAttribute("subnets");
@@ -511,12 +513,11 @@
}
/**
- * Set IP forwarding rule
- * - If the destination is the next hop, then do not push MPLS,
- * just decrease the NW TTL
- * - Otherwise, push MPLS label and set the MPLS ID
- *
- * @param sw target switch to set rules
+ * Set IP forwarding rule - If the destination is the next hop, then do not
+ * push MPLS, just decrease the NW TTL - Otherwise, push MPLS label and set
+ * the MPLS ID
+ *
+ * @param sw target switch to set rules
* @param subnetIp Match IP address
* @param mplsLabel MPLS label of final destination router
* @param fwdToSws next hop routers
@@ -528,7 +529,8 @@
Ipv4Match ipMatch = new Ipv4Match(subnetIp);
List<Action> actions = new ArrayList<>();
- // If destination SW is the same as the fwd SW, then do not push MPLS label
+ // If destination SW is the same as the fwd SW, then do not push MPLS
+ // label
if (fwdToSws.size() > 1) {
PushMplsAction pushMplsAction = new PushMplsAction();
@@ -549,7 +551,8 @@
}
else {
PushMplsAction pushMplsAction = new PushMplsAction();
- SetMplsIdAction setIdAction = new SetMplsIdAction(Integer.parseInt(mplsLabel));
+ SetMplsIdAction setIdAction = new SetMplsIdAction(
+ Integer.parseInt(mplsLabel));
CopyTtlOutAction copyTtlOutAction = new CopyTtlOutAction();
DecMplsTtlAction decMplsTtlAction = new DecMplsTtlAction(1);
@@ -569,14 +572,14 @@
// TODO: Mactch Action Id should be set correctly
MatchAction matchAction = new MatchAction(new MatchActionId(0),
- new SwitchPort((long)0,(short)0), ipMatch, actions);
+ new SwitchPort((long) 0, (short) 0), ipMatch, actions);
MatchActionOperationEntry maEntry =
- new MatchActionOperationEntry(
- net.onrc.onos.core.matchaction.MatchActionOperations.Operator.ADD,
- matchAction);
+ new MatchActionOperationEntry(
+ net.onrc.onos.core.matchaction.MatchActionOperations.Operator.ADD,
+ matchAction);
- IOF13Switch sw13 = (IOF13Switch)floodlightProvider.getMasterSwitch(
+ IOF13Switch sw13 = (IOF13Switch) floodlightProvider.getMasterSwitch(
getSwId(sw.getDpid().toString()));
try {
@@ -591,10 +594,9 @@
}
-
/**
* Convert a string DPID to its Switch Id (integer)
- *
+ *
* @param dpid
* @return
*/
@@ -602,7 +604,7 @@
long swId = 0;
- String swIdStr = dpid.substring(dpid.lastIndexOf(":")+1);
+ String swIdStr = dpid.substring(dpid.lastIndexOf(":") + 1);
if (swIdStr != null)
swId = Integer.parseInt(swIdStr);
@@ -610,14 +612,14 @@
}
/**
- * Set MPLS forwarding rules to MPLS table
- * - If the destination is the same as the next hop to forward packets
- * then, pop the MPLS label according to PHP rule
- * - Otherwise, just forward packets to next hops using Group action
- *
- * @param sw Switch to set the rules
+ * Set MPLS forwarding rules to MPLS table - If the destination is the same
+ * as the next hop to forward packets then, pop the MPLS label according to
+ * PHP rule - Otherwise, just forward packets to next hops using Group
+ * action
+ *
+ * @param sw Switch to set the rules
* @param mplsLabel destination MPLS label
- * @param fwdSws next hop switches
+ * @param fwdSws next hop switches
*/
private void setMplsTable(Switch sw, String mplsLabel, List<String> fwdSws) {
@@ -647,19 +649,19 @@
}
}
GroupAction groupAction = new GroupAction();
- for (String fwdSw: fwdSws)
+ for (String fwdSw : fwdSws)
groupAction.addSwitch(new Dpid(fwdSw));
actions.add(groupAction);
MatchAction matchAction = new MatchAction(new MatchActionId(0),
- new SwitchPort((long)0,(short)0), mplsMatch, actions);
+ new SwitchPort((long) 0, (short) 0), mplsMatch, actions);
MatchActionOperationEntry maEntry =
- new MatchActionOperationEntry(
- net.onrc.onos.core.matchaction.MatchActionOperations.Operator.ADD,
- matchAction);
+ new MatchActionOperationEntry(
+ net.onrc.onos.core.matchaction.MatchActionOperations.Operator.ADD,
+ matchAction);
- IOF13Switch sw13 = (IOF13Switch)floodlightProvider.getMasterSwitch(
+ IOF13Switch sw13 = (IOF13Switch) floodlightProvider.getMasterSwitch(
getSwId(sw.getDpid().toString()));
try {
@@ -671,10 +673,9 @@
}
-
/**
* Debugging function to print out the Match Action Entry
- *
+ *
* @param maEntry
*/
private void printMatchActionOperationEntry(Switch sw,
@@ -700,7 +701,7 @@
}
logStr.append(" do { ");
- for (Action action: actions) {
+ for (Action action : actions) {
if (action instanceof CopyTtlInAction) {
logStr.append("copy ttl In, ");
}
@@ -712,7 +713,7 @@
}
else if (action instanceof GroupAction) {
logStr.append("Forward packet to < ");
- NeighborSet dpids = ((GroupAction)action).getDpids();
+ NeighborSet dpids = ((GroupAction) action).getDpids();
logStr.append(dpids.toString() + ",");
}
@@ -723,7 +724,7 @@
logStr.append("Push MPLS label, ");
}
else if (action instanceof SetMplsIdAction) {
- int id = ((SetMplsIdAction)action).getMplsId();
+ int id = ((SetMplsIdAction) action).getMplsId();
logStr.append("Set MPLS ID as " + id + ", ");
}
@@ -735,15 +736,15 @@
/**
* Get MPLS label reading the config file
- *
- * @param dipid DPID of the switch
+ *
+ * @param dipid DPID of the switch
* @return MPLS label for the switch
*/
private String getMplsLabel(String dpid) {
String mplsLabel = null;
- for (Switch sw: mutableTopology.getSwitches()) {
+ for (Switch sw : mutableTopology.getSwitches()) {
String dpidStr = sw.getDpid().toString();
if (dpid.equals(dpidStr)) {
mplsLabel = sw.getStringAttribute("nodeSid");
@@ -754,16 +755,19 @@
return mplsLabel;
}
-
-
/**
* The function checks if given IP matches to the given subnet mask
- *
+ *
* @param addr - subnet address to match
* @param addr1 - IP address to check
* @return true if the IP address matches to the subnet, otherwise false
*/
- public boolean netMatch(String addr, String addr1){ //addr is subnet address and addr1 is ip address. Function will return true, if addr1 is within addr(subnet)
+ public boolean netMatch(String addr, String addr1) { // addr is subnet
+ // address and addr1 is
+ // ip address. Function
+ // will return true, if
+ // addr1 is within
+ // addr(subnet)
String[] parts = addr.split("/");
String ip = parts[0];
@@ -775,24 +779,25 @@
prefix = Integer.parseInt(parts[1]);
}
- Inet4Address a =null;
- Inet4Address a1 =null;
+ Inet4Address a = null;
+ Inet4Address a1 = null;
try {
a = (Inet4Address) InetAddress.getByName(ip);
a1 = (Inet4Address) InetAddress.getByName(addr1);
- } catch (UnknownHostException e){}
+ } catch (UnknownHostException e) {
+ }
byte[] b = a.getAddress();
int ipInt = ((b[0] & 0xFF) << 24) |
- ((b[1] & 0xFF) << 16) |
- ((b[2] & 0xFF) << 8) |
- ((b[3] & 0xFF) << 0);
+ ((b[1] & 0xFF) << 16) |
+ ((b[2] & 0xFF) << 8) |
+ ((b[3] & 0xFF) << 0);
byte[] b1 = a1.getAddress();
int ipInt1 = ((b1[0] & 0xFF) << 24) |
- ((b1[1] & 0xFF) << 16) |
- ((b1[2] & 0xFF) << 8) |
- ((b1[3] & 0xFF) << 0);
+ ((b1[1] & 0xFF) << 16) |
+ ((b1[2] & 0xFF) << 8) |
+ ((b1[3] & 0xFF) << 0);
int mask = ~((1 << (32 - prefix)) - 1);
@@ -806,7 +811,7 @@
/**
* Add a routing rule for the host
- *
+ *
* @param sw - Switch to add the rule
* @param hostIpAddress Destination host IP address
* @param hostMacAddress Destination host MAC address
@@ -818,7 +823,7 @@
/**
* Add IP packet to a buffer queue
- *
+ *
* @param ipv4
*/
public void addPacket(IPv4 ipv4) {
@@ -827,7 +832,7 @@
/**
* Retrieve all packets whose destination is the given address.
- *
+ *
* @param destIp Destination address of packets to retrieve
*/
public List<IPv4> getIpPacketFromQueue(byte[] destIp) {
@@ -835,12 +840,12 @@
List<IPv4> bufferedPackets = new ArrayList<IPv4>();
if (!ipPacketQueue.isEmpty()) {
- for (IPv4 ip: ipPacketQueue) {
+ for (IPv4 ip : ipPacketQueue) {
int dest = ip.getDestinationAddress();
IPv4Address ip1 = IPv4Address.of(dest);
IPv4Address ip2 = IPv4Address.of(destIp);
if (ip1.equals(ip2)) {
- bufferedPackets.add((IPv4)(ipPacketQueue.poll()).clone());
+ bufferedPackets.add((IPv4) (ipPacketQueue.poll()).clone());
}
}
}