Skip to content

Commit

Permalink
add capturedPacket info for live traffic
Browse files Browse the repository at this point in the history
  • Loading branch information
luolanzone committed May 10, 2021
1 parent f78ca7b commit 750c93d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
48 changes: 46 additions & 2 deletions pkg/graphviz/traceflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func GenGraph(tf *crdv1alpha1.Traceflow) (string, error) {
graph.Attrs[gographviz.Label] = getTraceflowStatusMessage(tf)
}
if tf == nil || senderRst == nil || tf.Status.Phase != crdv1alpha1.Succeeded || len(senderRst.Observations) == 0 {
// For live traffic, when the source is IP or empty, there is no sender's Node result from traceflow status.
// For live traffic, when the source is IP or empty, there is no result from the sender Node result in the traceflow status.
if senderRst == nil && tf.Spec.LiveTraffic && tf.Status.Phase == crdv1alpha1.Succeeded {
// Draw the nodes for the sender.
srcCluster, err := createClusterWithDefaultStyle(graph, clusterSrcName)
Expand All @@ -359,7 +359,7 @@ func GenGraph(tf *crdv1alpha1.Traceflow) (string, error) {
}
srcCluster.Attrs[gographviz.Label] = "source"
srcCluster.Attrs[gographviz.LabelJust] = "l"
// for live traffic data, we only know src IP from CapturedPacket
// For live traffic data, we only know src IP from capturedPacket
node, err := createEndpointNodeWithDefaultStyle(graph, srcCluster.Name, getWrappedStr(tf.Status.CapturedPacket.SrcIP))
if err != nil {
return "", err
Expand All @@ -381,6 +381,16 @@ func GenGraph(tf *crdv1alpha1.Traceflow) (string, error) {
if err != nil {
return "", err
}
// Add captured packet info to destination cluster.
err = graph.AddNode(dstCluster.Name, "capturedPacket", map[string]string{
"shape": "note",
"style": `"rounded,filled,solid"`,
"color": dimGrey,
"label": `"` + getCapturedPacketLabel(tf) + `"`,
})
if err != nil {
return "", err
}
// Draw the cross-cluster edge.
edge, err := createDirectedEdgeWithDefaultStyle(graph, node, nodes[len(nodes)-1], true)
if err != nil {
Expand Down Expand Up @@ -478,3 +488,37 @@ func GenGraph(tf *crdv1alpha1.Traceflow) (string, error) {

return genOutput(graph, false), nil
}

func getCapturedPacketLabel(tf *crdv1alpha1.Traceflow) string {
label := "caputredPacket:\\ldstIP:" + tf.Status.CapturedPacket.DstIP + "\\l"

if tf.Status.CapturedPacket.IPHeader != (crdv1alpha1.IPHeader{}) {
label = label + "ipHeader: " + "\\l" +
" flags: " + strconv.Itoa(int(tf.Status.CapturedPacket.IPHeader.Flags)) + "\\l" +
" protocol: " + strconv.Itoa(int(tf.Status.CapturedPacket.IPHeader.Protocol)) + "\\l" +
" ttl: " + strconv.Itoa(int(tf.Status.CapturedPacket.IPHeader.TTL)) + "\\l"
}

if tf.Status.CapturedPacket.IPv6Header != nil {
label = label + "ipv6Header: \\l" + " nextHeader: " +
strconv.Itoa(int(*tf.Status.CapturedPacket.IPv6Header.NextHeader)) + "\\l" +
" hopLimit: " + strconv.Itoa(int(tf.Status.CapturedPacket.IPv6Header.HopLimit)) + "\\l"
}

label = label + "length: " + strconv.Itoa(int(tf.Status.CapturedPacket.Length)) + "\\l" +
"srcIP: " + tf.Status.CapturedPacket.SrcIP + "\\l"

if tf.Status.CapturedPacket.TransportHeader != (crdv1alpha1.TransportHeader{}) {
if tf.Status.CapturedPacket.TransportHeader.TCP != nil {
label = label + " tcp: " + "\\l" +
" srcPort:" + strconv.Itoa(int(tf.Status.CapturedPacket.TransportHeader.TCP.SrcPort)) + "\\l" +
" dstPort:" + strconv.Itoa(int(tf.Status.CapturedPacket.TransportHeader.TCP.DstPort))
}
if tf.Status.CapturedPacket.TransportHeader.UDP != nil {
label = label + " udp: " + "\\l" +
" srcPort:" + strconv.Itoa(int(tf.Status.CapturedPacket.TransportHeader.UDP.SrcPort)) + "\\l" +
" dstPort:" + strconv.Itoa(int(tf.Status.CapturedPacket.TransportHeader.UDP.DstPort))
}
}
return label
}
8 changes: 4 additions & 4 deletions plugins/octant/cmd/antrea-octant-plugin/traceflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ func (p *antreaOctantPlugin) actionHandler(request *service.ActionRequest) error
return nil
}

// Judge whether the name of trace flow is duplicated.
// If it is, then the user creates more than one traceflows in one second, which is not allowed.
// Judge whether the name of traceflow is duplicated.
// If it is, then the user created more than one traceflow in one second, which is not allowed.
tfName := sourceName + "-" + dst + "-" + time.Now().Format(TIME_FORMAT_YYYYMMDD_HHMMSS)
ctx := context.Background()
err = p.checkDuplicateTf(tfName, ctx, request)
Expand Down Expand Up @@ -276,7 +276,7 @@ func (p *antreaOctantPlugin) actionHandler(request *service.ActionRequest) error
}

// Judge whether the name of trace flow is duplicated.
// If it is, then the user creates more than one traceflows in one second, which is not allowed.
// If it is, then the user created more than one traceflow in one second, which is not allowed.
tfName := ""
if srcLen == 0 {
tfName = "live-dst-" + dst + "-" + time.Now().Format(TIME_FORMAT_YYYYMMDD_HHMMSS)
Expand Down Expand Up @@ -822,7 +822,7 @@ func (p *antreaOctantPlugin) getSortedTfItems() []crdv1alpha1.Traceflow {
ctx := context.Background()
tfs, err := p.client.CrdV1alpha1().Traceflows().List(ctx, v1.ListOptions{ResourceVersion: "0"})
if err != nil {
log.Fatalf("Failed to get Traceflows %v", err)
log.Fatalf("Failed to get traceflows %v", err)
return nil
}
sort.Slice(tfs.Items, func(p, q int) bool {
Expand Down

0 comments on commit 750c93d

Please sign in to comment.