16 package org.openkilda.floodlight.model.flow;
22 import com.auth0.jwt.JWTCreator;
23 import com.auth0.jwt.interfaces.DecodedJWT;
24 import org.apache.commons.lang3.builder.EqualsBuilder;
25 import org.apache.commons.lang3.builder.HashCodeBuilder;
26 import org.projectfloodlight.openflow.types.DatapathId;
28 import java.util.UUID;
31 private static String JWT_KEY_PREFIX =
"flow.verification.";
33 private long sendTime = 0;
34 private long recvTime = 0;
35 private long senderLatency = 0;
37 private final DatapathId source;
38 private final DatapathId dest;
39 private final UUID packetId;
45 long recvTime = System.currentTimeMillis();
49 DatapathId source = DatapathId.of(token.getClaim(makeJwtKey(
"source")).asLong());
50 DatapathId dest = DatapathId.of(token.getClaim(makeJwtKey(
"dest")).asLong());
51 UUID packetId = UUID.fromString(token.getClaim(makeJwtKey(
"id")).asString());
54 data.setSenderLatency(token.getClaim(makeJwtKey(
"senderLatency")).asLong());
55 data.setSendTime(token.getClaim(makeJwtKey(
"time")).asLong());
56 data.setRecvTime(recvTime);
57 }
catch (NullPointerException e) {
59 String.format(
"Corrupted flow verification package (%s)", token));
69 DatapathId source = DatapathId.of(verificationRequest.getSourceSwitchId().toLong());
70 DatapathId dest = DatapathId.of(verificationRequest.getDestSwitchId().toLong());
71 return new VerificationData(source, dest, verificationRequest.getPacketId());
77 this.packetId = packetId;
83 public JWTCreator.Builder
toJwt(JWTCreator.Builder token) {
84 token.withClaim(makeJwtKey(
"source"), source.getLong());
85 token.withClaim(makeJwtKey(
"dest"), dest.getLong());
86 token.withClaim(makeJwtKey(
"id"), packetId.toString());
89 sendTime = System.currentTimeMillis();
90 token.withClaim(makeJwtKey(
"time"), sendTime);
110 private void setSendTime(
long sendTime) {
111 this.sendTime = sendTime;
118 private void setRecvTime(
long recvTime) {
119 this.recvTime = recvTime;
123 return senderLatency;
127 this.senderLatency = senderLatency;
147 if (o == null || getClass() != o.getClass()) {
153 return new EqualsBuilder()
154 .append(source, that.source)
155 .append(dest, that.dest)
156 .append(packetId, that.packetId)
162 return new HashCodeBuilder(17, 37)
169 private static String makeJwtKey(String
name) {
170 return JWT_KEY_PREFIX +
name;
static VerificationData of(DecodedJWT token)
static VerificationData of(UniFlowVerificationRequest verificationRequest)
VerificationData(DatapathId source, DatapathId dest, UUID packetId)
void setSenderLatency(long senderLatency)
VerificationMeasures produceMeasurements(long recipientLatency)
JWTCreator.Builder toJwt(JWTCreator.Builder token)