github.phpd.cn/cilium/cilium@v1.6.12/pkg/mtu/mtu_test.go (about)

     1  // Copyright 2018 Authors of Cilium
     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  // +build !privileged_tests
    16  
    17  package mtu
    18  
    19  import (
    20  	"testing"
    21  
    22  	. "gopkg.in/check.v1"
    23  )
    24  
    25  func Test(t *testing.T) { TestingT(t) }
    26  
    27  type MTUSuite struct{}
    28  
    29  var _ = Suite(&MTUSuite{})
    30  
    31  func (m *MTUSuite) TestNewConfiguration(c *C) {
    32  	// Add routes with no encryption or tunnel
    33  	conf := NewConfiguration(0, false, false, 0)
    34  	c.Assert(conf.GetDeviceMTU(), Not(Equals), 0)
    35  	c.Assert(conf.GetRouteMTU(), Equals, conf.GetDeviceMTU())
    36  
    37  	// Add routes with no encryption or tunnel and set MTU
    38  	conf = NewConfiguration(0, false, false, 1400)
    39  	c.Assert(conf.GetDeviceMTU(), Equals, 1400)
    40  	c.Assert(conf.GetRouteMTU(), Equals, conf.GetDeviceMTU())
    41  
    42  	// Add routes with tunnel
    43  	conf = NewConfiguration(0, false, true, 1400)
    44  	c.Assert(conf.GetDeviceMTU(), Equals, 1400)
    45  	c.Assert(conf.GetRouteMTU(), Equals, conf.GetDeviceMTU()-TunnelOverhead)
    46  
    47  	// Add routes with tunnel and set MTU
    48  	conf = NewConfiguration(0, false, true, 1400)
    49  	c.Assert(conf.GetDeviceMTU(), Equals, 1400)
    50  	c.Assert(conf.GetRouteMTU(), Equals, conf.GetDeviceMTU()-TunnelOverhead)
    51  
    52  	// Add routes with encryption and set MTU using standard 128bit, larger 256bit and smaller 96bit ICVlen keys
    53  	conf = NewConfiguration(16, true, false, 1400)
    54  	c.Assert(conf.GetDeviceMTU(), Equals, 1400)
    55  	c.Assert(conf.GetRouteMTU(), Equals, conf.GetDeviceMTU()-EncryptionIPsecOverhead)
    56  
    57  	conf = NewConfiguration(32, true, false, 1400)
    58  	c.Assert(conf.GetDeviceMTU(), Equals, 1400)
    59  	c.Assert(conf.GetRouteMTU(), Equals, conf.GetDeviceMTU()-(EncryptionIPsecOverhead+16))
    60  
    61  	conf = NewConfiguration(12, true, false, 1400)
    62  	c.Assert(conf.GetDeviceMTU(), Equals, 1400)
    63  	c.Assert(conf.GetRouteMTU(), Equals, conf.GetDeviceMTU()-(EncryptionIPsecOverhead-4))
    64  
    65  	// Add routes with encryption and tunnels using standard 128bit, larger 256bit and smaller 96bit ICVlen keys
    66  	conf = NewConfiguration(16, true, true, 1400)
    67  	c.Assert(conf.GetDeviceMTU(), Equals, 1400)
    68  	c.Assert(conf.GetRouteMTU(), Equals, conf.GetDeviceMTU()-(TunnelOverhead+EncryptionIPsecOverhead))
    69  
    70  	conf = NewConfiguration(32, true, true, 1400)
    71  	c.Assert(conf.GetDeviceMTU(), Equals, 1400)
    72  	c.Assert(conf.GetRouteMTU(), Equals, conf.GetDeviceMTU()-(TunnelOverhead+EncryptionIPsecOverhead+16))
    73  
    74  	conf = NewConfiguration(32, true, true, 1400)
    75  	c.Assert(conf.GetDeviceMTU(), Equals, 1400)
    76  	c.Assert(conf.GetRouteMTU(), Equals, conf.GetDeviceMTU()-(TunnelOverhead+EncryptionIPsecOverhead+16))
    77  }