import org.opendaylight.controller.sal.action.PopVlan;
import org.opendaylight.controller.sal.action.SetDlDst;
import org.opendaylight.controller.sal.action.SetDlSrc;
+import org.opendaylight.controller.sal.action.SetNextHop;
import org.opendaylight.controller.sal.action.SetNwDst;
import org.opendaylight.controller.sal.action.SetNwSrc;
import org.opendaylight.controller.sal.action.SetNwTos;
ANY, V4, V6;
};
- private enum SetNextHopType {
- CISCO_EXTENSION("Cisco NextHop Extension"), RESOLVE_L2RW(
- "Resolve L2 Rewrite");
-
- private SetNextHopType(String name) {
- this.name = name;
- }
-
- private String name;
-
- public String toString() {
- return name;
- }
-
- public boolean equals(String type) {
- if (type.trim().equalsIgnoreCase(name))
- return true;
- return false;
- }
- }
-
public FlowConfig() {
}
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
FlowConfig other = (FlowConfig) obj;
if (actions == null) {
- if (other.actions != null)
+ if (other.actions != null) {
return false;
- } else if (!actions.equals(other.actions))
+ }
+ } else if (!actions.equals(other.actions)) {
return false;
+ }
if (cookie == null) {
- if (other.cookie != null)
+ if (other.cookie != null) {
return false;
- } else if (!cookie.equals(other.cookie))
+ }
+ } else if (!cookie.equals(other.cookie)) {
return false;
+ }
if (dlDst == null) {
- if (other.dlDst != null)
+ if (other.dlDst != null) {
return false;
- } else if (!dlDst.equals(other.dlDst))
+ }
+ } else if (!dlDst.equals(other.dlDst)) {
return false;
+ }
if (dlSrc == null) {
- if (other.dlSrc != null)
+ if (other.dlSrc != null) {
return false;
- } else if (!dlSrc.equals(other.dlSrc))
+ }
+ } else if (!dlSrc.equals(other.dlSrc)) {
return false;
- if (dynamic != other.dynamic)
+ }
+ if (dynamic != other.dynamic) {
return false;
+ }
if (etherType == null) {
- if (other.etherType != null)
+ if (other.etherType != null) {
return false;
- } else if (!etherType.equals(other.etherType))
+ }
+ } else if (!etherType.equals(other.etherType)) {
return false;
+ }
if (ingressPort == null) {
- if (other.ingressPort != null)
+ if (other.ingressPort != null) {
return false;
- } else if (!ingressPort.equals(other.ingressPort))
+ }
+ } else if (!ingressPort.equals(other.ingressPort)) {
return false;
+ }
if (name == null) {
- if (other.name != null)
+ if (other.name != null) {
return false;
- } else if (!name.equals(other.name))
+ }
+ } else if (!name.equals(other.name)) {
return false;
+ }
if (nwDst == null) {
- if (other.nwDst != null)
+ if (other.nwDst != null) {
return false;
- } else if (!nwDst.equals(other.nwDst))
+ }
+ } else if (!nwDst.equals(other.nwDst)) {
return false;
+ }
if (nwSrc == null) {
- if (other.nwSrc != null)
+ if (other.nwSrc != null) {
return false;
- } else if (!nwSrc.equals(other.nwSrc))
+ }
+ } else if (!nwSrc.equals(other.nwSrc)) {
return false;
+ }
if (portGroup == null) {
- if (other.portGroup != null)
+ if (other.portGroup != null) {
return false;
- } else if (!portGroup.equals(other.portGroup))
+ }
+ } else if (!portGroup.equals(other.portGroup)) {
return false;
+ }
if (priority == null) {
- if (other.priority != null)
+ if (other.priority != null) {
return false;
- } else if (!priority.equals(other.priority))
+ }
+ } else if (!priority.equals(other.priority)) {
return false;
+ }
if (protocol == null) {
- if (other.protocol != null)
+ if (other.protocol != null) {
return false;
- } else if (!protocol.equals(other.protocol))
+ }
+ } else if (!protocol.equals(other.protocol)) {
return false;
+ }
if (node == null) {
- if (other.node != null)
+ if (other.node != null) {
return false;
- } else if (!node.equals(other.node))
+ }
+ } else if (!node.equals(other.node)) {
return false;
+ }
if (tosBits == null) {
- if (other.tosBits != null)
+ if (other.tosBits != null) {
return false;
- } else if (!tosBits.equals(other.tosBits))
+ }
+ } else if (!tosBits.equals(other.tosBits)) {
return false;
+ }
if (tpDst == null) {
- if (other.tpDst != null)
+ if (other.tpDst != null) {
return false;
- } else if (!tpDst.equals(other.tpDst))
+ }
+ } else if (!tpDst.equals(other.tpDst)) {
return false;
+ }
if (tpSrc == null) {
- if (other.tpSrc != null)
+ if (other.tpSrc != null) {
return false;
- } else if (!tpSrc.equals(other.tpSrc))
+ }
+ } else if (!tpSrc.equals(other.tpSrc)) {
return false;
+ }
if (vlanId == null) {
- if (other.vlanId != null)
+ if (other.vlanId != null) {
return false;
- } else if (!vlanId.equals(other.vlanId))
+ }
+ } else if (!vlanId.equals(other.vlanId)) {
return false;
+ }
if (vlanPriority == null) {
- if (other.vlanPriority != null)
+ if (other.vlanPriority != null) {
return false;
- } else if (!vlanPriority.equals(other.vlanPriority))
+ }
+ } else if (!vlanPriority.equals(other.vlanPriority)) {
return false;
+ }
if (idleTimeout == null) {
- if (other.idleTimeout != null)
+ if (other.idleTimeout != null) {
return false;
- } else if (!idleTimeout.equals(other.idleTimeout))
+ }
+ } else if (!idleTimeout.equals(other.idleTimeout)) {
return false;
+ }
if (hardTimeout == null) {
- if (other.hardTimeout != null)
+ if (other.hardTimeout != null) {
return false;
- } else if (!hardTimeout.equals(other.hardTimeout))
- return false;
- return true;
- }
-
- public InetAddress getNextHopAddressForL2RWAction() {
- if (actions != null) {
- Matcher sstr;
- for (String actiongrp : actions) {
- sstr = Pattern.compile("SET_NEXT_HOP=(.*)").matcher(actiongrp);
- if (sstr.matches()) {
- SetNextHopType setNHType = SetNextHopType.CISCO_EXTENSION;
- String nextHopInfo = sstr.group(1);
- String values[] = nextHopInfo.split("//");
- String address = values[0].trim();
- String type = null;
- if (values.length > 1) {
- type = values[1].trim();
- }
-
- if (type != null) {
- for (SetNextHopType nh : SetNextHopType.values()) {
- if (nh.equals(type))
- setNHType = nh;
- }
- }
-
- log.debug("Get Nexthop address = {} Type = {}", address,
- setNHType.toString());
- if (setNHType == SetNextHopType.RESOLVE_L2RW) {
- try {
- return InetAddress.getByName(address);
- } catch (Exception e) {
- log.debug(
- "Exception during nextHopAddress resolution : ",
- e);
- }
- }
- }
}
+ } else if (!hardTimeout.equals(other.hardTimeout)) {
+ return false;
}
- return null;
- }
-
- public String getNextHopL2RWUsageError() {
- return "Could not resolve NextHop IP Address for the selected Switch.<br>"
- + "Please Check the following configurations.<br>"
- + "1. Is the NextHop IP address directly connected to the Selected Switch<br>"
- + "2. If appropriate Subnet Configurations are done in the Switch Manager<br>"
- + "3. If the Nexthop IP-Address is Correct";
+ return true;
}
public boolean isL2AddressValid(String mac) {
}
// make sure it's a valid number
- if (cookie != null)
+ if (cookie != null) {
Long.decode(cookie);
+ }
if (ingressPort != null) {
Short port = Short.decode(ingressPort);
"Ethernet type %s is not valid", etherType));
return false;
} else {
- if (type == 0x800)
+ if (type == 0x800) {
etype = EtherIPType.V4;
- else if (type == 0x86dd)
+ } else if (type == 0x86dd) {
etype = EtherIPType.V6;
+ }
}
}
ActionType.SET_NEXT_HOP.toString() + "=(.*)")
.matcher(actiongrp);
if (sstr.matches()) {
- String nextHopInfo = sstr.group(1);
- String values[] = nextHopInfo.split("//");
- String address = values[0].trim();
-
- if ((address == null) || !isOutputNextHopValid(address)) {
+ if (!NetUtils.isIPAddressValid(sstr.group(1))) {
resultStr.append(String.format(
- "next hop %s is not valid", sstr.group(1)));
+ "IP destination address %s is not valid",
+ sstr.group(1)));
return false;
}
continue;
return flow;
}
- public boolean isOutputNextHopValid(String onh) {
- if (onh == null) {
- return false;
- }
- /*
- * For now, only takes IPv4 or IPv6 address
- */
- return (NetUtils.isIPv4AddressValid(onh) || NetUtils
- .isIPv6AddressValid(onh));
- }
-
public boolean isByNameAndNodeIdEqual(FlowConfig that) {
return (this.name.equals(that.name) && this.node.equals(that.node));
}
return this.node.equals(node);
}
- public static List<String> getSupportedNextHopTypes() {
- List<String> s = new ArrayList<String>();
- for (SetNextHopType nh : SetNextHopType.values()) {
- s.add(nh.toString());
- }
- return s;
- }
-
public void toggleStatus() {
installInHw = (installInHw == null) ? "true" : (installInHw
.equals("true")) ? "false" : "true";
ActionType.SET_NEXT_HOP.toString() + "=(.*)").matcher(
actiongrp);
if (sstr.matches()) {
- log.warn("We do not handle next hop action yet....");
+ actionList.add(new SetNextHop(NetUtils.parseInetAddress(sstr
+ .group(1))));
continue;
}
}
/**
* Returns the match in OF 1.0 (OFMatch) form or OF 1.0 + IPv6 extensions
* form (V6Match)
- *
+ *
* @return
*/
public OFMatch getOFMatch() {
* actually the DSCP field followed by a zero ECN
*/
byte tos = (Byte) match.getField(MatchType.NW_TOS).getValue();
- byte dscp = (byte) ((int) tos << 2);
+ byte dscp = (byte) (tos << 2);
if (!isIPv6) {
ofMatch.setNetworkTypeOfService(dscp);
wildcards &= ~OFMatch.OFPFW_NW_TOS;
/**
* Returns the list of actions in OF 1.0 form
- *
+ *
* @return
*/
public List<OFAction> getOFActions() {
continue;
}
if (action.getType() == ActionType.SET_NEXT_HOP) {
- // TODO
+ logger.info("Unsupported action: {}", action);
continue;
}
}
/**
* Utility to convert a SAL flow to an OF 1.0 (OFFlowMod) or to an OF 1.0 +
* IPv6 extension (V6FlowMod) Flow modifier Message
- *
+ *
* @param sw
* @param command
* @param port
if (ofMatch.getInputPort() != 0) {
salMatch.setField(new MatchField(MatchType.IN_PORT,
NodeConnectorCreator.createNodeConnector(
- (Short) ofMatch.getInputPort(), node)));
+ ofMatch.getInputPort(), node)));
}
if (ofMatch.getDataLayerSource() != null
&& !NetUtils
}
if (ofMatch.getTransportSource() != 0) {
salMatch.setField(MatchType.TP_SRC,
- ((Short) ofMatch.getTransportSource()));
+ ofMatch.getTransportSource());
}
if (ofMatch.getTransportDestination() != 0) {
salMatch.setField(MatchType.TP_DST,
- ((Short) ofMatch.getTransportDestination()));
+ ofMatch.getTransportDestination());
}
} else {
// Compute OF1.0 + IPv6 extensions Match
// Mask on input port is not defined
salMatch.setField(new MatchField(MatchType.IN_PORT,
NodeConnectorCreator.createOFNodeConnector(
- (Short) v6Match.getInputPort(), node)));
+ v6Match.getInputPort(), node)));
}
if (v6Match.getDataLayerSource() != null
&& !NetUtils
}
if (v6Match.getTransportSource() != 0) {
salMatch.setField(MatchType.TP_SRC,
- ((Short) v6Match.getTransportSource()));
+ (v6Match.getTransportSource()));
}
if (v6Match.getTransportDestination() != 0) {
salMatch.setField(MatchType.TP_DST,
- ((Short) v6Match.getTransportDestination()));
+ (v6Match.getTransportDestination()));
}
}
}
* @return the integer number
*/
public static int byteArray4ToInt(byte[] ba) {
- if (ba == null || ba.length != 4)
+ if (ba == null || ba.length != 4) {
return 0;
- return (int) ((0xff & ba[0]) << 24 | (0xff & ba[1]) << 16
- | (0xff & ba[2]) << 8 | (0xff & ba[3]));
+ }
+ return (0xff & ba[0]) << 24 | (0xff & ba[1]) << 16
+ | (0xff & ba[2]) << 8 | (0xff & ba[3]);
}
/**
int intMask = 0;
int numBytes = prefixMask.length;
for (int i = 0; i < numBytes; i++) {
- intMask |= ((int) prefixMask[i] & 0xff) << (8 * (numBytes - 1 - i));
+ intMask |= (prefixMask[i] & 0xff) << (8 * (numBytes - 1 - i));
}
int bit = 1;
if (isAny(testAddress) || isAny(filterAddress)) {
return false;
}
-
+
int testMaskLen = (testMask != null) ? NetUtils.getSubnetMaskLength(testMask.getAddress()) : 0;
int filterMaskLen = (filterMask != null) ? NetUtils.getSubnetMaskLength(filterMask.getAddress()) : 0;
-
+
int testPrefixLen = (testAddress instanceof Inet6Address) ? (128 - testMaskLen) : (32 - testMaskLen);
int filterPrefixLen = (filterAddress instanceof Inet6Address) ? (128 - filterMaskLen) : (32 - filterMaskLen);
-
+
// Mask length check. Test mask has to be more specific than filter one
if (testPrefixLen < filterPrefixLen) {
return true;
* @return
*/
public static boolean isIPv4AddressValid(String cidr) {
- if (cidr == null)
+ if (cidr == null) {
return false;
+ }
String values[] = cidr.split("/");
Pattern ipv4Pattern = Pattern
* @return
*/
public static boolean isIPv6AddressValid(String cidr) {
- if (cidr == null)
+ if (cidr == null) {
return false;
+ }
String values[] = cidr.split("/");
try {
}
return true;
}
-
+
+ /**
+ * Checks if the passed IP address in string form is a valid v4 or v6
+ * address. The address may specify a mask at the end as "/MMM"
+ *
+ * @param cidr
+ * the v4 or v6 address as IP/MMM
+ * @return
+ */
+ public static boolean isIPAddressValid(String cidr) {
+ return NetUtils.isIPv4AddressValid(cidr)
+ || NetUtils.isIPv6AddressValid(cidr);
+ }
+
/*
- * Following utilities are useful when you need to
+ * Following utilities are useful when you need to
* compare or bit shift java primitive type variable
* which are inerently signed
*/
/**
* Returns the unsigned value of the passed byte variable
- *
+ *
* @param b the byte value
* @return the int variable containing the unsigned byte value
*/
public static int getUnsignedByte(byte b) {
- return (b > 0)? (int)b : ((int)b & 0x7F | 0x80);
+ return (b > 0)? (int)b : (b & 0x7F | 0x80);
}
-
+
/**
* Return the unsigned value of the passed short variable
- *
+ *
* @param s the short value
* @return the int variable containing the unsigned short value
*/
public static int getUnsignedShort(short s) {
- return (s > 0)? (int)s : ((int)s & 0x7FFF | 0x8000);
+ return (s > 0)? (int)s : (s & 0x7FFF | 0x8000);
}
}