16 package org.openkilda.simulator.classes;
26 import org.projectfloodlight.openflow.types.DatapathId;
28 import java.io.IOException;
29 import java.time.Instant;
30 import java.util.Random;
31 import java.util.UUID;
34 private static final int MAX_SMALL = 50;
35 private static final int MAX_LARGE = 10000;
37 private Random rand =
new Random();
39 private long rxPackets = 0;
40 private long txPackets = 0;
41 private long rxBytes = 0;
42 private long txBytes = 0;
43 private long rxDropped = 0;
44 private long txDropped = 0;
45 private long rxErrors = 0;
46 private long txErrors = 0;
47 private long rxFrameErr = 0;
48 private long rxOverErr = 0;
49 private long rxCrcErr = 0;
50 private long collisions = 0;
53 private int latency = 0;
54 private DatapathId peerSwitch;
55 private int peerPortNum = -1;
65 throw new SimulatorException(String.format(
"Unknown port state %s", state.toString()));
83 return new InfoMessage(
data, Instant.now().toEpochMilli(), UUID.randomUUID().toString(), null);
89 this.isForwarding =
true;
94 this.isActive =
false;
95 this.isForwarding =
false;
100 this.isForwarding =
false;
105 this.isForwarding =
true;
130 this.latency = latency;
140 return peerSwitch.toString();
145 this.peerSwitch = DatapathId.of(peerSwitch);
150 this.peerPortNum = peerPortNum;
159 public void setIsl(DatapathId peerSwitch,
int peerPortNum) {
160 this.peerSwitch = peerSwitch;
161 this.peerPortNum = peerPortNum;
180 this.rxPackets += rand.nextInt(MAX_LARGE);
181 this.txPackets += rand.nextInt(MAX_LARGE);
182 this.rxBytes += rand.nextInt(MAX_LARGE);
183 this.txBytes += rand.nextInt(MAX_LARGE);
184 this.rxDropped += rand.nextInt(MAX_SMALL);
185 this.txDropped += rand.nextInt(MAX_SMALL);
186 this.rxErrors += rand.nextInt(MAX_SMALL);
187 this.txErrors += rand.nextInt(MAX_SMALL);
188 this.rxFrameErr += rand.nextInt(MAX_SMALL);
189 this.rxOverErr += rand.nextInt(MAX_SMALL);
190 this.rxCrcErr += rand.nextInt(MAX_SMALL);
191 this.collisions += rand.nextInt(MAX_SMALL);
194 return new PortStatsEntry(this.number, this.rxPackets, this.txPackets, this.rxBytes, this.txBytes,
195 this.rxDropped, this.txDropped, this.rxErrors, this.txErrors, this.rxFrameErr, this.rxOverErr,
196 this.rxCrcErr, this.collisions);
void setLatency(int latency)
void setSw(ISwitchImpl sw)
void setPeerPortNum(int peerPortNum)
void setPeerSwitch(String peerSwitch)
IPortImpl(ISwitchImpl sw, PortStateType state, int portNumber)
void modPort(PortModMessage message)
void setIsl(DatapathId peerSwitch, int peerPortNum)
PortStatsEntry getStats()
InfoMessage makePorChangetMessage()