Disallow illegal link types in lib/topology.
@@ -185,6 +185,9 @@ func (t *Topo) populateBR(raw *RawTopo) error {
if ifinfo.LinkType, err = LinkTypeFromString(rawIntf.LinkTo); err != nil {
return err
}
+ if err = ifinfo.Verify(t.Core, name); err != nil {
+ return err
+ }
ifinfo.MTU = rawIntf.MTU
t.IFInfoMap[ifid] = ifinfo
@@ -285,6 +288,25 @@ type IFInfo struct {
MTU int
}
+func (i IFInfo) Verify(isCore bool, brName string) error {
+ if isCore {
+ switch i.LinkType {
+ case proto.LinkType_core, proto.LinkType_child:
+ default:
+ return common.NewBasicError("Illegal link type for core AS", nil,
+ "type", i.LinkType, "br", brName)
+ }
+ } else {
+ switch i.LinkType {
+ case proto.LinkType_parent, proto.LinkType_child, proto.LinkType_peer:
+ default:
+ return common.NewBasicError("Illegal link type for non-core AS", nil,
+ "type", i.LinkType, "br", brName)
+ }
+ }
+ return nil
+}
+
func (i IFInfo) String() string {
return fmt.Sprintf("IFinfo: Name[%s] IntAddr[%+v] CtrlAddr[%+v] Overlay:%s Local:%+v "+
"Remote:+%v Bw:%d IA:%s Type:%s MTU:%d", i.BRName, i.InternalAddrs, i.CtrlAddrs, i.Overlay,
