go.ligato.io/vpp-agent/v3@v3.5.0/proto/ligato/vpp/punt/models_test.go (about)

     1  //  Copyright (c) 2018 Cisco and/or its affiliates.
     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 vpp_punt
    16  
    17  /*func TestPuntToHostKey(t *testing.T) {
    18  	tests := []struct {
    19  		name        string
    20  		l3Protocol  L3Protocol
    21  		l4Protocol  L4Protocol
    22  		port        uint32
    23  		expectedKey string
    24  	}{
    25  		{
    26  			name:        "valid Punt case (IPv4/UDP)",
    27  			l3Protocol:  L3Protocol_IPv4,
    28  			l4Protocol:  L4Protocol_UDP,
    29  			port:        9000,
    30  			expectedKey: "vpp/config/v2/punt/tohost/l3/IPv4/l4/UDP/port/9000",
    31  		},
    32  		{
    33  			name:        "valid Punt case (IPv4/TCP)",
    34  			l3Protocol:  L3Protocol_IPv4,
    35  			l4Protocol:  L4Protocol_TCP,
    36  			port:        9000,
    37  			expectedKey: "vpp/config/v2/punt/tohost/l3/IPv4/l4/TCP/port/9000",
    38  		},
    39  		{
    40  			name:        "valid Punt case (IPv6/UDP)",
    41  			l3Protocol:  L3Protocol_IPv6,
    42  			l4Protocol:  L4Protocol_UDP,
    43  			port:        9000,
    44  			expectedKey: "vpp/config/v2/punt/tohost/l3/IPv6/l4/UDP/port/9000",
    45  		},
    46  		{
    47  			name:        "valid Punt case (IPv6/TCP)",
    48  			l3Protocol:  L3Protocol_IPv6,
    49  			l4Protocol:  L4Protocol_TCP,
    50  			port:        0,
    51  			expectedKey: "vpp/config/v2/punt/tohost/l3/IPv6/l4/TCP/port/<invalid>",
    52  		},
    53  		{
    54  			name:        "invalid Punt case (zero port)",
    55  			l3Protocol:  L3Protocol_IPv4,
    56  			l4Protocol:  L4Protocol_UDP,
    57  			port:        0,
    58  			expectedKey: "vpp/config/v2/punt/tohost/l3/IPv4/l4/UDP/port/<invalid>",
    59  		},
    60  	}
    61  	for _, test := range tests {
    62  		t.Run(test.name, func(t *testing.T) {
    63  			key := ToHostKey(test.l3Protocol, test.l4Protocol, test.port)
    64  			if key != test.expectedKey {
    65  				t.Errorf("failed for: puntName=%s\n"+
    66  					"expected key:\n\t%q\ngot key:\n\t%q",
    67  					test.name, test.expectedKey, key)
    68  			}
    69  		})
    70  	}
    71  }*/
    72  
    73  /*func TestParsePuntToHostKey(t *testing.T) {
    74  	tests := []struct {
    75  		name            string
    76  		key             string
    77  		expectedL3      L3Protocol
    78  		expectedL4      L4Protocol
    79  		expectedPort    uint32
    80  		isPuntToHostKey bool
    81  	}{
    82  		{
    83  			name:            "valid Punt key",
    84  			key:             "vpp/config/v2/punt/tohost/l3/IPv4/l4/TCP/port/9000",
    85  			expectedL3:      L3Protocol(4),
    86  			expectedL4:      L4Protocol(6),
    87  			expectedPort:    9000,
    88  			isPuntToHostKey: true,
    89  		},
    90  		{
    91  			name:            "invalid Punt L3",
    92  			key:             "vpp/config/v2/punt/tohost/l3/4/l4/TCP/port/9000",
    93  			expectedL3:      L3Protocol(0),
    94  			expectedL4:      L4Protocol(6),
    95  			expectedPort:    9000,
    96  			isPuntToHostKey: true,
    97  		},
    98  		{
    99  			name:            "invalid Punt L3 and L4",
   100  			key:             "vpp/config/v2/punt/tohost/l3/4/l4/6/port/9000",
   101  			expectedL3:      L3Protocol(0),
   102  			expectedL4:      L4Protocol(0),
   103  			expectedPort:    9000,
   104  			isPuntToHostKey: true,
   105  		},
   106  		{
   107  			name:            "invalid Punt L4 and port",
   108  			key:             "vpp/config/v2/punt/tohost/l3/IPv6/l4/17/port/port1",
   109  			expectedL3:      L3Protocol(6),
   110  			expectedL4:      L4Protocol(0),
   111  			expectedPort:    0,
   112  			isPuntToHostKey: true,
   113  		},
   114  		{
   115  			name:            "invalid all",
   116  			key:             "vpp/config/v2/punt/tohost/l3/4/l4/17/port/port1",
   117  			expectedL3:      L3Protocol(0),
   118  			expectedL4:      L4Protocol(0),
   119  			expectedPort:    0,
   120  			isPuntToHostKey: true,
   121  		},
   122  		{
   123  			name:            "not a Punt to host key",
   124  			key:             "vpp/config/v2/punt/ipredirect/l3/IPv6/tx/if1",
   125  			expectedL3:      L3Protocol(0),
   126  			expectedL4:      L4Protocol(0),
   127  			expectedPort:    0,
   128  			isPuntToHostKey: false,
   129  		},
   130  	}
   131  	for _, test := range tests {
   132  		t.Run(test.name, func(t *testing.T) {
   133  			l3Proto, l4Proto, port, isPuntToHostKey := ParsePuntToHostKey(test.key)
   134  			if l3Proto != test.expectedL3 {
   135  				t.Errorf("expected l3PuntKey: %v\tgot: %v", test.expectedL3, l3Proto)
   136  			}
   137  			if l4Proto != test.expectedL4 {
   138  				t.Errorf("expected l4PuntKey: %v\tgot: %v", test.expectedL4, l4Proto)
   139  			}
   140  			if port != test.expectedPort {
   141  				t.Errorf("expected portPuntKey: %v\tgot: %v", test.expectedPort, port)
   142  			}
   143  			if isPuntToHostKey != test.isPuntToHostKey {
   144  				t.Errorf("expected isPuntKey: %v\tgot: %v", test.isPuntToHostKey, isPuntToHostKey)
   145  			}
   146  		})
   147  	}
   148  }*/
   149  
   150  /*func TestIPredirectKey(t *testing.T) {
   151  	tests := []struct {
   152  		name        string
   153  		l3Protocol  L3Protocol
   154  		txInterface string
   155  		expectedKey string
   156  	}{
   157  		{
   158  			name:        "valid IP redirect case (IPv4)",
   159  			l3Protocol:  L3Protocol_IPv4,
   160  			txInterface: "if1",
   161  			expectedKey: "vpp/config/v2/punt/ipredirect/l3/IPv4/tx/if1",
   162  		},
   163  		{
   164  			name:        "valid IP redirect case (IPv6)",
   165  			l3Protocol:  L3Protocol_IPv6,
   166  			txInterface: "if1",
   167  			expectedKey: "vpp/config/v2/punt/ipredirect/l3/IPv6/tx/if1",
   168  		},
   169  		{
   170  			name:        "invalid IP redirect case (undefined interface)",
   171  			l3Protocol:  L3Protocol_IPv4,
   172  			txInterface: "",
   173  			expectedKey: "vpp/config/v2/punt/ipredirect/l3/IPv4/tx/<invalid>",
   174  		},
   175  	}
   176  	for _, test := range tests {
   177  		t.Run(test.name, func(t *testing.T) {
   178  			key := IPRedirectKey(test.l3Protocol, test.txInterface)
   179  			if key != test.expectedKey {
   180  				t.Errorf("failed for: puntName=%s\n"+
   181  					"expected key:\n\t%q\ngot key:\n\t%q",
   182  					test.name, test.expectedKey, key)
   183  			}
   184  		})
   185  	}
   186  }*/
   187  
   188  /*func TestParseIPRedirectKey(t *testing.T) {
   189  	tests := []struct {
   190  		name            string
   191  		key             string
   192  		expectedL3      L3Protocol
   193  		expectedIf      string
   194  		isIPRedirectKey bool
   195  	}{
   196  		{
   197  			name:            "valid IP redirect key (IPv4)",
   198  			key:             "vpp/config/v2/punt/ipredirect/l3/IPv4/tx/if1",
   199  			expectedL3:      L3Protocol(4),
   200  			expectedIf:      "if1",
   201  			isIPRedirectKey: true,
   202  		},
   203  		{
   204  			name:            "valid IP redirect key (IPv6)",
   205  			key:             "vpp/config/v2/punt/ipredirect/l3/IPv6/tx/if1",
   206  			expectedL3:      L3Protocol(6),
   207  			expectedIf:      "if1",
   208  			isIPRedirectKey: true,
   209  		},
   210  		{
   211  			name:            "invalid IP redirect key (invalid interface)",
   212  			key:             "vpp/config/v2/punt/ipredirect/l3/IPv4/tx/<invalid>",
   213  			expectedL3:      L3Protocol(4),
   214  			expectedIf:      "<invalid>",
   215  			isIPRedirectKey: true,
   216  		},
   217  	}
   218  	for _, test := range tests {
   219  		t.Run(test.name, func(t *testing.T) {
   220  			l3Proto, ifName, isIPRedirectKey := ParseIPRedirectKey(test.key)
   221  			if l3Proto != test.expectedL3 {
   222  				t.Errorf("expected l3IPRedirectKey L3: %v\tgot: %v", test.expectedL3, l3Proto)
   223  			}
   224  			if ifName != test.expectedIf {
   225  				t.Errorf("expected l3IPRedirectKey ifName: %v\tgot: %v", test.expectedIf, ifName)
   226  			}
   227  			if isIPRedirectKey != test.isIPRedirectKey {
   228  				t.Errorf("expected isIPRedirectKey: %v\tgot: %v", test.isIPRedirectKey, isIPRedirectKey)
   229  			}
   230  		})
   231  	}
   232  }*/