Skip to content

Commit 8454c7e

Browse files
committed
Add Port VLAN configuration API.
1 parent 179814b commit 8454c7e

File tree

5 files changed

+63
-1
lines changed

5 files changed

+63
-1
lines changed

src/main/java/com/cisco/trex/stateless/TRexClient.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,14 @@ public EthernetPacket sendIcmpV6Echo(int portIndex, String dstIp, int icmpId, in
697697
return new IPv6NeighborDiscoveryService(this).sendIcmpV6Echo(portIndex, dstIp, icmpId, icmpSeq, timeOut);
698698
}
699699

700+
public TRexClientResult<StubResult> setVlan(int portIdx, List<Integer> vlanIds) {
701+
Map<String, Object> parameters = new HashMap<>();
702+
parameters.put("port_id", portIdx);
703+
parameters.put("vlan", vlanIds);
704+
705+
return callMethod("set_vlan", parameters, StubResult.class);
706+
}
707+
700708
private class ApiVersionResponse {
701709
private String id;
702710
private String jsonrpc;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.cisco.trex.stateless.model;
2+
3+
public class StubResult {
4+
}

src/main/java/com/cisco/trex/stateless/model/port/PortAttributes.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ public class PortAttributes {
2626

2727
@JsonProperty("speed")
2828
private int speed;
29+
30+
@JsonProperty("vlan")
31+
private PortVlan vlan;
2932

3033
@JsonProperty("fc")
3134
public PortFCAttribute getFlowControl() {
@@ -96,4 +99,14 @@ public int getSpeed() {
9699
public void setSpeed(int speed) {
97100
this.speed = speed;
98101
}
102+
103+
@JsonProperty("vlan")
104+
public PortVlan getVlan() {
105+
return vlan;
106+
}
107+
108+
@JsonProperty("vlan")
109+
public void setVlan(PortVlan vlan) {
110+
this.vlan = vlan;
111+
}
99112
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.cisco.trex.stateless.model.port;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
6+
import java.util.List;
7+
8+
@JsonIgnoreProperties(ignoreUnknown = true)
9+
public class PortVlan {
10+
@JsonProperty("tags")
11+
public List<Integer> tags;
12+
13+
@JsonProperty("tags")
14+
public List<Integer> getTags() {
15+
return tags;
16+
}
17+
18+
@JsonProperty("tags")
19+
public void setTags(List<Integer> tags) {
20+
this.tags = tags;
21+
}
22+
}

src/test/java/com/cisco/trex/stateless/TRexClientTest.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
import com.cisco.trex.stateless.model.capture.CaptureMonitor;
1010
import com.cisco.trex.stateless.model.capture.CaptureMonitorStop;
1111
import com.cisco.trex.stateless.model.capture.CapturedPackets;
12+
import com.cisco.trex.stateless.model.port.PortVlan;
1213
import org.junit.*;
1314
import org.pcap4j.packet.ArpPacket;
1415
import org.pcap4j.packet.EthernetPacket;
15-
§import org.pcap4j.packet.IllegalRawDataException;
16+
import org.pcap4j.packet.IllegalRawDataException;
1617
import org.pcap4j.packet.Packet;
1718
import org.pcap4j.packet.namednumber.ArpHardwareType;
1819
import org.pcap4j.packet.namednumber.ArpOperation;
@@ -39,6 +40,20 @@ public static void setUp() throws TRexConnectionException, TRexTimeoutException
3940
client.connect();
4041
}
4142

43+
@Test
44+
public void setVlanTest() {
45+
List<Port> ports = client.getPorts();
46+
Port port = ports.get(0);
47+
client.acquirePort(port.index, true);
48+
TRexClientResult<StubResult> result = client.setVlan(port.index, Arrays.asList(23, 34));
49+
Assert.assertTrue(!result.isFailed());
50+
51+
PortStatus portStatus = getPortStatus(port.index);
52+
PortVlan vlan = portStatus.getAttr().getVlan();
53+
Assert.assertTrue(vlan.tags.get(0).equals(23));
54+
Assert.assertTrue(vlan.tags.get(1).equals(34));
55+
}
56+
4257
@Test
4358
public void getPortsTest() {
4459
List<Port> ports = client.getPorts();

0 commit comments

Comments
 (0)