-
-
Notifications
You must be signed in to change notification settings - Fork 402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve PI unique packet generation #1945
Changes from all commits
e0f21d1
58870d6
1092b48
53b47ea
24ced98
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,25 +46,25 @@ var ( | |
id uint16 | ||
count uint64 | ||
interval uint64 | ||
increment bool | ||
mode string | ||
incrementPayload int64 | ||
ttl uint8 | ||
) | ||
|
||
// AddInjectPacketInjectFlags add the command line flags for a packet injection | ||
func AddInjectPacketInjectFlags(cmd *cobra.Command) { | ||
cmd.Flags().StringVarP(&srcIP, "srcIP", "", "", "source node IP") | ||
cmd.Flags().StringVarP(&dstIP, "dstIP", "", "", "destination node IP") | ||
cmd.Flags().StringVarP(&srcMAC, "srcMAC", "", "", "source node MAC") | ||
cmd.Flags().StringVarP(&dstMAC, "dstMAC", "", "", "destination node MAC") | ||
cmd.Flags().Uint16VarP(&srcPort, "srcPort", "", 0, "source port for TCP packet") | ||
cmd.Flags().Uint16VarP(&dstPort, "dstPort", "", 0, "destination port for TCP packet") | ||
cmd.Flags().StringVarP(&srcIP, "src-ip", "", "", "source node IP") | ||
cmd.Flags().StringVarP(&dstIP, "dst-ip", "", "", "destination node IP") | ||
cmd.Flags().StringVarP(&srcMAC, "src-mac", "", "", "source node MAC") | ||
cmd.Flags().StringVarP(&dstMAC, "dst-mac", "", "", "destination node MAC") | ||
cmd.Flags().Uint16VarP(&srcPort, "src-port", "", 0, "source port for TCP packet") | ||
cmd.Flags().Uint16VarP(&dstPort, "dst-port", "", 0, "destination port for TCP packet") | ||
cmd.Flags().StringVarP(&packetType, "type", "", "icmp4", "packet type: icmp4, icmp6, tcp4, tcp6, udp4 and udp6") | ||
cmd.Flags().StringVarP(&payload, "payload", "", "", "payload") | ||
cmd.Flags().StringVar(&pcap, "pcap", "", "PCAP file") | ||
cmd.Flags().Uint16VarP(&id, "id", "", 0, "ICMP identification") | ||
cmd.Flags().BoolVarP(&increment, "increment", "", false, "increment ICMP id for each packet") | ||
cmd.Flags().Int64VarP(&incrementPayload, "incrementPayload", "", 0, "increase payload for each packet") | ||
cmd.Flags().StringVarP(&mode, "mode", "", "unique", "specify mode of packet generation, `unique` or `random`") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice to check if the specified value is either "unique" or "random" |
||
cmd.Flags().Int64VarP(&incrementPayload, "inc-payload", "", 0, "increase payload size each packet") | ||
cmd.Flags().Uint64VarP(&count, "count", "", 1, "number of packets to be generated") | ||
cmd.Flags().Uint64VarP(&interval, "interval", "", 0, "wait interval milliseconds between sending each packet") | ||
cmd.Flags().Uint8VarP(&ttl, "ttl", "", 64, "IP time-to-live header") | ||
|
@@ -110,7 +110,7 @@ func GetPacketInjectRequest() (*pi.PacketInjectionRequest, error) { | |
Count: count, | ||
ICMPID: id, | ||
Interval: interval, | ||
Increment: increment, | ||
Mode: mode, | ||
IncrementPayload: incrementPayload, | ||
Payload: payload, | ||
Pcap: pcapContent, | ||
|
@@ -199,8 +199,8 @@ var InjectPacketCmd = &cobra.Command{ | |
} | ||
|
||
func init() { | ||
InjectPacketCmd.Flags().StringVarP(&ifName, "ifName", "", "", "interface to inject packets into") | ||
InjectPacketCmd.Flags().StringVarP(&encapType, "encapType", "", "ether", "encapsulation type") | ||
InjectPacketCmd.Flags().StringVarP(&ifName, "if-name", "", "", "interface to inject packets into") | ||
InjectPacketCmd.Flags().StringVarP(&encapType, "encap-type", "", "ether", "encapsulation type") | ||
AddInjectPacketInjectFlags(InjectPacketCmd) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,15 +69,33 @@ func (h *onDemandFlowHandler) ResourceName() string { | |
return "Capture" | ||
} | ||
|
||
func (h *onDemandFlowHandler) GetNodes(resource types.Resource) []interface{} { | ||
func (h *onDemandFlowHandler) GetNodeResources(resource types.Resource) []client.OnDemandNodeResource { | ||
var nrs []client.OnDemandNodeResource | ||
|
||
capture := resource.(*types.Capture) | ||
|
||
query := capture.GremlinQuery | ||
query += fmt.Sprintf(".Dedup().Has('Captures.ID', NEE('%s'))", resource.ID()) | ||
if capture.Type != "" && !common.CheckProbeCapabilities(capture.Type, common.MultipleOnSameNodeCapability) { | ||
query += fmt.Sprintf(".Has('Captures.Type', NEE('%s'))", capture.Type) | ||
} | ||
query += h.nodeTypeQuery | ||
return h.applyGremlinExpr(query) | ||
|
||
if nodes := h.applyGremlinExpr(query); len(nodes) > 0 { | ||
for _, i := range nodes { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this be done in applyGremlinExpr ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. applyGremlinExpr is called somewhere else so I would prefer to keep this as it is |
||
switch i.(type) { | ||
case *graph.Node: | ||
nrs = append(nrs, client.OnDemandNodeResource{Node: i.(*graph.Node), Resource: capture}) | ||
case []*graph.Node: | ||
// case of shortestpath that returns a list of nodes | ||
for _, node := range i.([]*graph.Node) { | ||
nrs = append(nrs, client.OnDemandNodeResource{Node: node, Resource: capture}) | ||
} | ||
} | ||
} | ||
} | ||
|
||
return nrs | ||
} | ||
|
||
func (h *onDemandFlowHandler) applyGremlinExpr(query string) []interface{} { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is these changes needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really but make command line more consistent, this doesn't break the API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1