[CORD-2583] Change Fpm protocol classes to use Builder pattern
Change-Id: Ia91b5c07529dabddb7d828bb0352143d4a6083a9
diff --git a/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/FpmManager.java b/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/FpmManager.java
index 56d193e..e290aea 100644
--- a/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/FpmManager.java
+++ b/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/FpmManager.java
@@ -75,7 +75,6 @@
import org.slf4j.LoggerFactory;
import java.net.InetSocketAddress;
-import java.util.ArrayList;
import java.time.Duration;
import java.util.Collection;
import java.util.Collections;
@@ -531,24 +530,23 @@
private void sendRouteUpdateToChannel(boolean isAdd, IpPrefix prefix, Channel ch) {
- int netLinkLength;
- short addrFamily;
- IpAddress pdPushNextHop;
-
if (!pdPushEnabled) {
return;
}
try {
- // Construct list of route attributes.
- List<RouteAttribute> attributes = new ArrayList<>();
+ int raLength;
+ short addrFamily;
+ IpAddress pdPushNextHop;
+
+ // Build route attributes.
if (prefix.isIp4()) {
if (pdPushNextHopIPv4 == null) {
log.info("Prefix not pushed because ipv4 next-hop is null.");
return;
}
pdPushNextHop = pdPushNextHopIPv4;
- netLinkLength = Ip4Address.BYTE_LENGTH + RouteAttribute.ROUTE_ATTRIBUTE_HEADER_LENGTH;
+ raLength = Ip4Address.BYTE_LENGTH + RouteAttribute.ROUTE_ATTRIBUTE_HEADER_LENGTH;
addrFamily = RtNetlink.RT_ADDRESS_FAMILY_INET;
} else {
if (pdPushNextHopIPv6 == null) {
@@ -556,70 +554,48 @@
return;
}
pdPushNextHop = pdPushNextHopIPv6;
- netLinkLength = Ip6Address.BYTE_LENGTH + RouteAttribute.ROUTE_ATTRIBUTE_HEADER_LENGTH;
+ raLength = Ip6Address.BYTE_LENGTH + RouteAttribute.ROUTE_ATTRIBUTE_HEADER_LENGTH;
addrFamily = RtNetlink.RT_ADDRESS_FAMILY_INET6;
}
- RouteAttributeDst raDst = new RouteAttributeDst(
- netLinkLength,
- RouteAttribute.RTA_DST,
- prefix.address());
- attributes.add(raDst);
+ RouteAttributeDst raDst = RouteAttributeDst.builder()
+ .length(raLength)
+ .type(RouteAttribute.RTA_DST)
+ .dstAddress(prefix.address())
+ .build();
- RouteAttributeGateway raGateway = new RouteAttributeGateway(
- netLinkLength,
- RouteAttribute.RTA_GATEWAY,
- pdPushNextHop);
- attributes.add(raGateway);
+ RouteAttributeGateway raGateway = RouteAttributeGateway.builder()
+ .length(raLength)
+ .type(RouteAttribute.RTA_GATEWAY)
+ .gateway(pdPushNextHop)
+ .build();
- // Add RtNetlink header.
- int srcLength = 0;
- short tos = 0;
- short table = 0;
- short scope = 0;
- long rtFlags = 0;
+ // Build RtNetlink.
+ RtNetlink rtNetlink = RtNetlink.builder()
+ .addressFamily(addrFamily)
+ .dstLength(prefix.prefixLength())
+ .routeAttribute(raDst)
+ .routeAttribute(raGateway)
+ .build();
+
+ // Build Netlink.
int messageLength = raDst.length() + raGateway.length() +
- RtNetlink.RT_NETLINK_LENGTH;
+ RtNetlink.RT_NETLINK_LENGTH + Netlink.NETLINK_HEADER_LENGTH;
+ Netlink netLink = Netlink.builder()
+ .length(messageLength)
+ .type(isAdd ? NetlinkMessageType.RTM_NEWROUTE : NetlinkMessageType.RTM_DELROUTE)
+ .flags(Netlink.NETLINK_REQUEST | Netlink.NETLINK_CREATE)
+ .rtNetlink(rtNetlink)
+ .build();
- RtNetlink rtNetlink = new RtNetlink(
- addrFamily,
- prefix.prefixLength(),
- srcLength,
- tos,
- table,
- RtProtocol.ZEBRA,
- scope,
- FpmHeader.FPM_TYPE_NETLINK,
- rtFlags,
- attributes);
-
- // Add Netlink header.
- NetlinkMessageType nlMsgType;
- if (isAdd) {
- nlMsgType = NetlinkMessageType.RTM_NEWROUTE;
- } else {
- nlMsgType = NetlinkMessageType.RTM_DELROUTE;
- }
- int flags = Netlink.NETLINK_REQUEST | Netlink.NETLINK_CREATE;
- long sequence = 0;
- long processPortId = 0;
- messageLength += Netlink.NETLINK_HEADER_LENGTH;
-
- Netlink netLink = new Netlink(messageLength,
- nlMsgType,
- flags,
- sequence,
- processPortId,
- rtNetlink);
-
+ // Build FpmHeader.
messageLength += FpmHeader.FPM_HEADER_LENGTH;
-
- // Add FpmHeader.
- FpmHeader fpmMessage = new FpmHeader(
- FpmHeader.FPM_VERSION_1,
- FpmHeader.FPM_TYPE_NETLINK,
- messageLength,
- netLink);
+ FpmHeader fpmMessage = FpmHeader.builder()
+ .version(FpmHeader.FPM_VERSION_1)
+ .type(FpmHeader.FPM_TYPE_NETLINK)
+ .length(messageLength)
+ .netlink(netLink)
+ .build();
// Encode message in a channel buffer and transmit.
ch.write(fpmMessage.encode());
diff --git a/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/FpmHeader.java b/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/FpmHeader.java
index 607c9e1..abaaa88 100644
--- a/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/FpmHeader.java
+++ b/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/FpmHeader.java
@@ -63,7 +63,7 @@
* @param length length
* @param netlink netlink header
*/
- public FpmHeader(short version, short type, int length, Netlink netlink) {
+ private FpmHeader(short version, short type, int length, Netlink netlink) {
this.version = version;
this.type = type;
this.length = length;
@@ -169,4 +169,83 @@
netlink.encode(cb);
return cb;
}
+
+ /**
+ * Returns a new FpmHeader builder.
+ *
+ * @return FpmHeader builder
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ /**
+ * FpmHeader Builder.
+ */
+ public static final class Builder {
+
+ private short version = FPM_VERSION_1;
+ private short type = FPM_TYPE_NETLINK;
+ private int length = 0;
+ private Netlink netlink = null;
+
+ /**
+ * Hide class constructor.
+ */
+ private Builder() {
+ }
+
+ /**
+ * Sets version for the FpmHeader that will be built.
+ *
+ * @param version to use for built FpmHeader
+ * @return this builder
+ */
+ public Builder version(short version) {
+ this.version = version;
+ return this;
+ }
+
+ /**
+ * Sets type for the FpmHeader that will be built.
+ *
+ * @param type to use for built FpmHeader
+ * @return this builder
+ */
+ public Builder type(short type) {
+ this.type = type;
+ return this;
+ }
+
+ /**
+ * Sets length for the FpmHeader that will be built.
+ *
+ * @param length to use for built FpmHeader
+ * @return this builder
+ */
+ public Builder length(int length) {
+ this.length = length;
+ return this;
+ }
+
+ /**
+ * Sets netlink for the FpmHeader that will be built.
+ *
+ * @param netlink to use for built FpmHeader
+ * @return this builder
+ */
+ public Builder netlink(Netlink netlink) {
+ this.netlink = netlink;
+ return this;
+ }
+
+ /**
+ * Builds the FpmHeader.
+ *
+ * @return FpmHeader reference
+ */
+ public FpmHeader build() {
+ return new FpmHeader(version, type, length, netlink);
+ }
+ }
}
diff --git a/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/Netlink.java b/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/Netlink.java
index df84ed6..d7bdd26 100644
--- a/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/Netlink.java
+++ b/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/Netlink.java
@@ -55,7 +55,7 @@
* @param processPortId port ID
* @param rtNetlink netlink routing message
*/
- public Netlink(long length, NetlinkMessageType type, int flags, long sequence,
+ private Netlink(long length, NetlinkMessageType type, int flags, long sequence,
long processPortId, RtNetlink rtNetlink) {
this.length = length;
this.type = type;
@@ -188,4 +188,106 @@
rtNetlink.encode(cb);
}
+ /**
+ * Returns a new Netlink builder.
+ *
+ * @return Netlink builder
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ /**
+ * Netlink Builder.
+ */
+ public static final class Builder {
+
+ private long length = 0;
+ private NetlinkMessageType type = NetlinkMessageType.RTM_NEWROUTE;
+ private int flags = 0;
+ private long sequence = 0;
+ private long processPortId = 0;
+ private RtNetlink rtNetlink = null;
+
+ /**
+ * Hide class constructor.
+ */
+ private Builder() {
+ }
+
+ /**
+ * Sets length for the Netlink that will be built.
+ *
+ * @param length to use for built Netlink
+ * @return this builder
+ */
+ public Builder length(long length) {
+ this.length = length;
+ return this;
+ }
+
+ /**
+ * Sets type for the Netlink that will be built.
+ *
+ * @param type to use for built Netlink
+ * @return this builder
+ */
+ public Builder type(NetlinkMessageType type) {
+ this.type = type;
+ return this;
+ }
+
+ /**
+ * Sets flags for the Netlink that will be built.
+ *
+ * @param flags to use for built Netlink
+ * @return this builder
+ */
+ public Builder flags(int flags) {
+ this.flags = flags;
+ return this;
+ }
+
+ /**
+ * Sets sequence for the Netlink that will be built.
+ *
+ * @param sequence to use for built Netlink
+ * @return this builder
+ */
+ public Builder sequence(long sequence) {
+ this.sequence = sequence;
+ return this;
+ }
+
+ /**
+ * Sets processPortId for the Netlink that will be built.
+ *
+ * @param processPortId to use for built Netlink
+ * @return this builder
+ */
+ public Builder processPortId(long processPortId) {
+ this.processPortId = processPortId;
+ return this;
+ }
+
+ /**
+ * Sets rtNetlink for the Netlink that will be built.
+ *
+ * @param rtNetlink to use for built Netlink
+ * @return this builder
+ */
+ public Builder rtNetlink(RtNetlink rtNetlink) {
+ this.rtNetlink = rtNetlink;
+ return this;
+ }
+
+ /**
+ * Builds the Netlink.
+ *
+ * @return Netlink reference
+ */
+ public Netlink build() {
+ return new Netlink(length, type, flags, sequence, processPortId, rtNetlink);
+ }
+ }
}
diff --git a/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/RouteAttribute.java b/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/RouteAttribute.java
index 43a21c0..280c678 100644
--- a/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/RouteAttribute.java
+++ b/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/RouteAttribute.java
@@ -121,6 +121,43 @@
*
* @param cb channelbuffer to be filled in
*/
- public abstract void encode(ChannelBuffer cb);
+ public void encode(ChannelBuffer cb) {
+ cb.writeShort(Short.reverseBytes((short) length()));
+ cb.writeShort(Short.reverseBytes((short) type()));
+ }
+ /**
+ * RouteAttribute Builder.
+ */
+ public abstract static class Builder<T extends Builder<T>> {
+
+ protected int length;
+ protected int type;
+
+ public Builder() {}
+
+ public abstract T getThis();
+
+ /**
+ * Sets length for RouteAttribute that will be built.
+ *
+ * @param length to use for built RtNetlink
+ * @return this generic builder type
+ */
+ public T length(int length) {
+ this.length = length;
+ return getThis();
+ }
+
+ /**
+ * Sets type for RouteAttribute that will be built.
+ *
+ * @param type to use for built RtNetlink
+ * @return this generic builder type
+ */
+ public T type(int type) {
+ this.type = type;
+ return getThis();
+ }
+ }
}
diff --git a/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/RouteAttributeDst.java b/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/RouteAttributeDst.java
index 2962c0b..f7e3d3b 100644
--- a/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/RouteAttributeDst.java
+++ b/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/RouteAttributeDst.java
@@ -38,7 +38,7 @@
* @param type type
* @param dstAddress destination address
*/
- public RouteAttributeDst(int length, int type, IpAddress dstAddress) {
+ private RouteAttributeDst(int length, int type, IpAddress dstAddress) {
super(length, type);
this.dstAddress = dstAddress;
@@ -91,8 +91,7 @@
@Override
public void encode(ChannelBuffer cb) {
- cb.writeShort(Short.reverseBytes((short) length()));
- cb.writeShort(Short.reverseBytes((short) type()));
+ super.encode(cb);
ChannelBuffer buffer = ChannelBuffers.copiedBuffer(dstAddress.toOctets());
if (length() == Ip6Address.BYTE_LENGTH +
@@ -105,4 +104,54 @@
throw new IllegalArgumentException("Dst address length incorrect!");
}
}
+
+ /**
+ * Returns a new RouteAttributeDst builder.
+ *
+ * @return RouteAttributeDst builder
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ /**
+ * RouteAttributeDst Builder.
+ */
+ public static final class Builder extends RouteAttribute.Builder<Builder> {
+
+ private IpAddress dstAddress = null;
+
+ /**
+ * Hide class constructor.
+ */
+ private Builder() {}
+
+ /**
+ * Override abstract method.
+ */
+ @Override
+ public Builder getThis() {
+ return this;
+ }
+
+ /**
+ * Sets dstAddress for RouteAttributeDst that will be built.
+ *
+ * @param dstAddress to use for built RouteAttributeDst
+ * @return this builder
+ */
+ public Builder dstAddress(IpAddress dstAddress) {
+ this.dstAddress = dstAddress;
+ return this;
+ }
+
+ /**
+ * Builds the RouteAttributeDst.
+ *
+ * @return RouteAttributeDst reference
+ */
+ public RouteAttributeDst build() {
+ return new RouteAttributeDst(length, type, dstAddress);
+ }
+ }
}
diff --git a/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/RouteAttributeGateway.java b/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/RouteAttributeGateway.java
index 3b1f5cd..ecf36d3 100644
--- a/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/RouteAttributeGateway.java
+++ b/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/RouteAttributeGateway.java
@@ -40,7 +40,7 @@
* @param type type
* @param gateway gateway address
*/
- public RouteAttributeGateway(int length, int type, IpAddress gateway) {
+ private RouteAttributeGateway(int length, int type, IpAddress gateway) {
super(length, type);
this.gateway = gateway;
@@ -93,8 +93,7 @@
@Override
public void encode(ChannelBuffer cb) {
- cb.writeShort(Short.reverseBytes((short) length()));
- cb.writeShort(Short.reverseBytes((short) type()));
+ super.encode(cb);
ChannelBuffer buffer = ChannelBuffers.copiedBuffer(gateway.toOctets());
if (length() == Ip6Address.BYTE_LENGTH +
@@ -107,4 +106,54 @@
throw new IllegalArgumentException("Gateway address length incorrect!");
}
}
+
+ /**
+ * Returns a new RouteAttributeGateway builder.
+ *
+ * @return RouteAttributeGateway builder
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ /**
+ * RouteAttributeGateway Builder.
+ */
+ public static final class Builder extends RouteAttribute.Builder<Builder> {
+
+ private IpAddress gateway = null;
+
+ /**
+ * Hide class constructor.
+ */
+ private Builder() {}
+
+ /**
+ * Override abstract method.
+ */
+ @Override
+ public Builder getThis() {
+ return this;
+ }
+
+ /**
+ * Sets gateway for RouteAttributeGateway that will be built.
+ *
+ * @param gateway to use for built RouteAttributeGateway
+ * @return this builder
+ */
+ public Builder gateway(IpAddress gateway) {
+ this.gateway = gateway;
+ return this;
+ }
+
+ /**
+ * Builds the RouteAttributeGateway.
+ *
+ * @return RouteAttributeGateway reference
+ */
+ public RouteAttributeGateway build() {
+ return new RouteAttributeGateway(length, type, gateway);
+ }
+ }
}
diff --git a/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/RouteAttributeOif.java b/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/RouteAttributeOif.java
index 49a12e8..e6becb7 100644
--- a/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/RouteAttributeOif.java
+++ b/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/RouteAttributeOif.java
@@ -38,7 +38,7 @@
* @param type type
* @param outputInterface output interface
*/
- public RouteAttributeOif(int length, int type, long outputInterface) {
+ private RouteAttributeOif(int length, int type, long outputInterface) {
super(length, type);
this.outputInterface = outputInterface;
@@ -87,8 +87,57 @@
@Override
public void encode(ChannelBuffer cb) {
- cb.writeShort(Short.reverseBytes((short) length()));
- cb.writeShort(Short.reverseBytes((short) type()));
+ super.encode(cb);
cb.writeInt(Integer.reverseBytes((int) outputInterface));
}
+
+ /**
+ * Returns a new RouteAttributeOif builder.
+ *
+ * @return RouteAttributeOif builder
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ /**
+ * RouteAttributeOif Builder.
+ */
+ public static final class Builder extends RouteAttribute.Builder<Builder> {
+
+ private long outputInterface = 0;
+
+ /**
+ * Hide class constructor.
+ */
+ private Builder() {}
+
+ /**
+ * Override abstract method.
+ */
+ @Override
+ public Builder getThis() {
+ return this;
+ }
+
+ /**
+ * Sets outputInterface for RouteAttributeOif that will be built.
+ *
+ * @param outputInterface to use for built RouteAttributeOif
+ * @return this builder
+ */
+ public Builder outputInterface(long outputInterface) {
+ this.outputInterface = outputInterface;
+ return this;
+ }
+
+ /**
+ * Builds the RouteAttributeOif.
+ *
+ * @return RouteAttributeOif reference
+ */
+ public RouteAttributeOif build() {
+ return new RouteAttributeOif(length, type, outputInterface);
+ }
+ }
}
diff --git a/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/RouteAttributePriority.java b/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/RouteAttributePriority.java
index 2c45db0..89dad43 100644
--- a/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/RouteAttributePriority.java
+++ b/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/RouteAttributePriority.java
@@ -38,7 +38,7 @@
* @param type type
* @param priority priority
*/
- public RouteAttributePriority(int length, int type, long priority) {
+ private RouteAttributePriority(int length, int type, long priority) {
super(length, type);
this.priority = priority;
@@ -87,8 +87,57 @@
@Override
public void encode(ChannelBuffer cb) {
- cb.writeShort(Short.reverseBytes((short) length()));
- cb.writeShort(Short.reverseBytes((short) type()));
+ super.encode(cb);
cb.writeInt(Integer.reverseBytes((int) priority));
}
+
+ /**
+ * Returns a new RouteAttributePriority builder.
+ *
+ * @return RouteAttributePriority builder
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ /**
+ * RouteAttributePriority Builder.
+ */
+ public static final class Builder extends RouteAttribute.Builder<Builder> {
+
+ private long priority = 0;
+
+ /**
+ * Hide class constructor.
+ */
+ private Builder() {}
+
+ /**
+ * Override abstract method.
+ */
+ @Override
+ public Builder getThis() {
+ return this;
+ }
+
+ /**
+ * Sets priority for RouteAttributePriority that will be built.
+ *
+ * @param priority to use for built RouteAttributePriority
+ * @return this builder
+ */
+ public Builder priority(long priority) {
+ this.priority = priority;
+ return this;
+ }
+
+ /**
+ * Builds the RouteAttributePriority.
+ *
+ * @return RouteAttributePriority reference
+ */
+ public RouteAttributePriority build() {
+ return new RouteAttributePriority(length, type, priority);
+ }
+ }
}
diff --git a/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/RtNetlink.java b/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/RtNetlink.java
index adaaf62..ef2faa4 100644
--- a/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/RtNetlink.java
+++ b/apps/routing/fpm/app/src/main/java/org/onosproject/routing/fpm/protocol/RtNetlink.java
@@ -67,7 +67,7 @@
* @param flags flags
* @param attributes list of attributes
*/
- public RtNetlink(short addressFamily,
+ private RtNetlink(short addressFamily,
int dstLength,
int srcLength,
short tos,
@@ -270,4 +270,163 @@
}
}
+ /**
+ * Returns a new RtNetlink builder.
+ *
+ * @return RtNetlink builder
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ /**
+ * RtNetlink Builder.
+ */
+ public static final class Builder {
+
+ private short addressFamily = RT_ADDRESS_FAMILY_INET;
+ private int dstLength = 0;
+ private int srcLength = 0;
+ private short tos = 0;
+ private short table = 0;
+ private RtProtocol protocol = RtProtocol.ZEBRA;
+ private short scope = 0;
+ private short type = FpmHeader.FPM_TYPE_NETLINK;
+ private long flags = 0;
+ private List<RouteAttribute> attributes = new ArrayList<>();
+
+ /**
+ * Hide class constructor.
+ */
+ private Builder() {
+ }
+
+ /**
+ * Sets addressFamily for the RtNetlink that will be built.
+ *
+ * @param addressFamily to use for built RtNetlink
+ * @return this builder
+ */
+ public Builder addressFamily(short addressFamily) {
+ this.addressFamily = addressFamily;
+ return this;
+ }
+
+ /**
+ * Sets dstLength for the RtNetlink that will be built.
+ *
+ * @param dstLength to use for built RtNetlink
+ * @return this builder
+ */
+ public Builder dstLength(int dstLength) {
+ this.dstLength = dstLength;
+ return this;
+ }
+
+ /**
+ * Sets srcLength for the RtNetlink that will be built.
+ *
+ * @param srcLength to use for built RtNetlink
+ * @return this builder
+ */
+ public Builder srcLength(int srcLength) {
+ this.srcLength = srcLength;
+ return this;
+ }
+
+ /**
+ * Sets tos for the RtNetlink that will be built.
+ *
+ * @param tos to use for built RtNetlink
+ * @return this builder
+ */
+ public Builder tos(short tos) {
+ this.tos = tos;
+ return this;
+ }
+
+ /**
+ * Sets table for the RtNetlink that will be built.
+ *
+ * @param table to use for built RtNetlink
+ * @return this builder
+ */
+ public Builder table(short table) {
+ this.table = table;
+ return this;
+ }
+
+ /**
+ * Sets protocol for the RtNetlink that will be built.
+ *
+ * @param protocol to use for built RtNetlink
+ * @return this builder
+ */
+ public Builder protocol(RtProtocol protocol) {
+ this.protocol = protocol;
+ return this;
+ }
+
+ /**
+ * Sets scope for the RtNetlink that will be built.
+ *
+ * @param scope to use for built RtNetlink
+ * @return this builder
+ */
+ public Builder scope(short scope) {
+ this.scope = scope;
+ return this;
+ }
+
+ /**
+ * Sets type for the RtNetlink that will be built.
+ *
+ * @param type to use for built RtNetlink
+ * @return this builder
+ */
+ public Builder type(short type) {
+ this.type = type;
+ return this;
+ }
+
+ /**
+ * Sets flags for the RtNetlink that will be built.
+ *
+ * @param flags to use for built RtNetlink
+ * @return this builder
+ */
+ public Builder flags(long flags) {
+ this.flags = flags;
+ return this;
+ }
+
+ /**
+ * Adds attribute for the RtNetlink that will be built.
+ *
+ * @param ra to add to list of route attributes
+ * @return this builder
+ */
+ public Builder routeAttribute(RouteAttribute ra) {
+ attributes.add(ra);
+ return this;
+ }
+
+ /**
+ * Builds the RtNetlink.
+ *
+ * @return RtNetlink reference
+ */
+ public RtNetlink build() {
+ return new RtNetlink(addressFamily,
+ dstLength,
+ srcLength,
+ tos,
+ table,
+ protocol,
+ scope,
+ type,
+ flags,
+ attributes);
+ }
+ }
}