|
| 1 | +// +build ebpf |
| 2 | + |
| 3 | +/* |
| 4 | + * Copyright (C) 2016 Red Hat, Inc. |
| 5 | + * |
| 6 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 7 | + * or more contributor license agreements. See the NOTICE file |
| 8 | + * distributed with this work for additional information |
| 9 | + * regarding copyright ownership. The ASF licenses this file |
| 10 | + * to you under the Apache License, Version 2.0 (the |
| 11 | + * "License"); you may not use this file except in compliance |
| 12 | + * with the License. You may obtain a copy of the License at |
| 13 | + * |
| 14 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 15 | + * |
| 16 | + * Unless required by applicable law or agreed to in writing, |
| 17 | + * software distributed under the License is distributed on an |
| 18 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 19 | + * KIND, either express or implied. See the License for the |
| 20 | + * specific language governing permissions and limitations |
| 21 | + * under the License. |
| 22 | + * |
| 23 | + */ |
| 24 | + |
| 25 | +package tests |
| 26 | + |
| 27 | +import ( |
| 28 | + "fmt" |
| 29 | + "testing" |
| 30 | + |
| 31 | + "github.com/skydive-project/skydive/common" |
| 32 | + "github.com/skydive-project/skydive/tests/helper" |
| 33 | +) |
| 34 | + |
| 35 | +func TestFlowsEBPF(t *testing.T) { |
| 36 | + test := &Test{ |
| 37 | + setupCmds: []helper.Cmd{ |
| 38 | + {"ovs-vsctl add-br br-ebpf", true}, |
| 39 | + |
| 40 | + {"ip netns add src-vm", true}, |
| 41 | + {"ip link add src-vm-eth0 type veth peer name ebpf-src-eth0 netns src-vm", true}, |
| 42 | + {"ip link set src-vm-eth0 up", true}, |
| 43 | + {"ip netns exec src-vm ip link set ebpf-src-eth0 up", true}, |
| 44 | + {"ip netns exec src-vm ip address add 169.254.107.33/24 dev ebpf-src-eth0", true}, |
| 45 | + |
| 46 | + {"ip netns add dst-vm", true}, |
| 47 | + {"ip link add dst-vm-eth0 type veth peer name ebpf-dst-eth0 netns dst-vm", true}, |
| 48 | + {"ip link set dst-vm-eth0 up", true}, |
| 49 | + {"ip netns exec dst-vm ip link set ebpf-dst-eth0 up", true}, |
| 50 | + {"ip netns exec dst-vm ip address add 169.254.107.34/24 dev ebpf-dst-eth0", true}, |
| 51 | + |
| 52 | + {"ovs-vsctl add-port br-ebpf src-vm-eth0", true}, |
| 53 | + {"ovs-vsctl add-port br-ebpf dst-vm-eth0", true}, |
| 54 | + }, |
| 55 | + |
| 56 | + setupFunction: func(c *TestContext) (err error) { |
| 57 | + return ping(t, c, 4, "G.V().Has('Name', 'ebpf-src-eth0')", "G.V().Has('Name', 'ebpf-dst-eth0')", 10, 0) |
| 58 | + }, |
| 59 | + |
| 60 | + tearDownCmds: []helper.Cmd{ |
| 61 | + {"ovs-vsctl del-br br-ebpf", true}, |
| 62 | + {"ip link del dst-vm-eth0", true}, |
| 63 | + {"ip link del src-vm-eth0", true}, |
| 64 | + {"ip netns del src-vm", true}, |
| 65 | + {"ip netns del dst-vm", true}, |
| 66 | + }, |
| 67 | + |
| 68 | + captures: []TestCapture{ |
| 69 | + {gremlin: `G.V().Has('Name', 'ebpf-src-eth0')`, kind: "ebpf"}, |
| 70 | + }, |
| 71 | + |
| 72 | + checks: []CheckFunction{func(c *CheckContext) error { |
| 73 | + g := "g" |
| 74 | + if !c.time.IsZero() { |
| 75 | + g += fmt.Sprintf(".Context(%d)", common.UnixMillis(c.time)) |
| 76 | + } |
| 77 | + gremlin := g + ".Flows().Has('Network', '169.254.107.33', 'LayersPath', 'Ethernet/IPv4/ICMPv4').Dedup()" |
| 78 | + flows, err := c.gh.GetFlows(gremlin) |
| 79 | + if err != nil { |
| 80 | + return err |
| 81 | + } |
| 82 | + if len(flows) != 1 || flows[0].Metric.ABPackets != 10 { |
| 83 | + return fmt.Errorf("Expected one flow, got %+v", flows) |
| 84 | + } |
| 85 | + |
| 86 | + return nil |
| 87 | + }}, |
| 88 | + } |
| 89 | + RunTest(t, test) |
| 90 | +} |
0 commit comments