| 1 | // Copyright 2016 CNI authors |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package testutils |
| 16 | |
| 17 | import ( |
| 18 | "github.com/containernetworking/cni/pkg/version" |
| 19 | ) |
| 20 | |
| 21 | // AllSpecVersions contains all CNI spec version numbers |
| 22 | var AllSpecVersions = [...]string{"0.1.0", "0.2.0", "0.3.0", "0.3.1", "0.4.0", "1.0.0", "1.1.0"} |
| 23 | |
| 24 | // SpecVersionHasIPVersion returns true if the given CNI specification version |
| 25 | // includes the "version" field in the IP address elements |
| 26 | func SpecVersionHasIPVersion(ver string) bool { |
| 27 | for _, i := range []string{"0.3.0", "0.3.1", "0.4.0"} { |
| 28 | if ver == i { |
| 29 | return true |
| 30 | } |
| 31 | } |
| 32 | return false |
| 33 | } |
| 34 | |
| 35 | // SpecVersionHasCHECK returns true if the given CNI specification version |
| 36 | // supports the CHECK command |
| 37 | func SpecVersionHasCHECK(ver string) bool { |
| 38 | ok, _ := version.GreaterThanOrEqualTo(ver, "0.4.0") |
| 39 | return ok |
| 40 | } |
| 41 | |
| 42 | // SpecVersionHasSTATUS returns true if the given CNI specification version |
| 43 | // supports the STATUS command |
| 44 | func SpecVersionHasSTATUS(ver string) bool { |
| 45 | ok, _ := version.GreaterThanOrEqualTo(ver, "1.1.0") |
| 46 | return ok |
| 47 | } |
| 48 | |
| 49 | // SpecVersionHasChaining returns true if the given CNI specification version |
| 50 | // supports plugin chaining |
| 51 | func SpecVersionHasChaining(ver string) bool { |
| 52 | ok, _ := version.GreaterThanOrEqualTo(ver, "0.3.0") |
| 53 | return ok |
| 54 | } |
| 55 | |
| 56 | // SpecVersionHasMultipleIPs returns true if the given CNI specification version |
| 57 | // supports more than one IP address of each family |
| 58 | func SpecVersionHasMultipleIPs(ver string) bool { |
| 59 | ok, _ := version.GreaterThanOrEqualTo(ver, "0.3.0") |
| 60 | return ok |
| 61 | } |