github.com/osrg/gobgp@v2.0.0+incompatible/internal/pkg/table/roa.go (about)

     1  // Copyright (C) 2016 Nippon Telegraph and Telephone Corporation.
     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
    12  // implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  
    16  package table
    17  
    18  import (
    19  	"fmt"
    20  	"net"
    21  )
    22  
    23  type IPPrefix struct {
    24  	Prefix net.IP
    25  	Length uint8
    26  }
    27  
    28  func (p *IPPrefix) String() string {
    29  	return fmt.Sprintf("%s/%d", p.Prefix, p.Length)
    30  }
    31  
    32  type ROA struct {
    33  	Family int
    34  	Prefix *IPPrefix
    35  	MaxLen uint8
    36  	AS     uint32
    37  	Src    string
    38  }
    39  
    40  func NewROA(family int, prefixByte []byte, prefixLen uint8, maxLen uint8, as uint32, src string) *ROA {
    41  	p := make([]byte, len(prefixByte))
    42  	copy(p, prefixByte)
    43  	return &ROA{
    44  		Family: family,
    45  		Prefix: &IPPrefix{
    46  			Prefix: p,
    47  			Length: prefixLen,
    48  		},
    49  		MaxLen: maxLen,
    50  		AS:     as,
    51  		Src:    src,
    52  	}
    53  }
    54  
    55  func (r *ROA) Equal(roa *ROA) bool {
    56  	if r.MaxLen == roa.MaxLen && r.Src == roa.Src && r.AS == roa.AS {
    57  		return true
    58  	}
    59  	return false
    60  }