func (b *BgpNeighborsEntity) SetRouteMapIn(name string, value string) bool {
	cmd := b.CommandBuilder(name, "route-map", value, false, true)
	cmd = cmd + " in"
	return b.Configure(cmd)
}
SetRouteMapIn sets the neighbor name(string) inbound route-map entry using
value(string)
Returns true(bool) if the commands complete successfully
package module
import (
	"net"
	"regexp"
	"strconv"
	"github.com/aristanetworks/goeapi"
)
type BgpNetworkEntry map[string]string
type BgpConfig struct {
	asNumber     string
	routerID     string
	shutdown     string
	maxPaths     string
	maxEcmpPaths string
	networks     []BgpNetworkEntry
}
func (b *BgpConfig) BgpAs() string {
	return b.asNumber
}
func (b *BgpConfig) RouterID() string {
	return b.routerID
}
func (b *BgpConfig) Shutdown() string {
	return b.shutdown
}
func (b *BgpConfig) MaximumPaths() string {
	return b.maxPaths
}
func (b *BgpConfig) MaximumEcmpPaths() string {
	return b.maxEcmpPaths
}
func (b *BgpConfig) Networks() []BgpNetworkEntry {
	return b.networks
}
func (b BgpNetworkEntry) Prefix() string {
	return b["prefix"]
}
func (b BgpNetworkEntry) MaskLen() string {
	return b["masklen"]
}
func (b BgpNetworkEntry) RouteMap() string {
	return b["route_map"]
}
type BGPEntity struct {
	neighbors *BgpNeighborsEntity
	*AbstractBaseEntity
}
func Bgp(node *goeapi.Node) *BGPEntity {
	return &BGPEntity{AbstractBaseEntity: &AbstractBaseEntity{node}}
}
func (b *BGPEntity) Get() *BgpConfig {
	config, err := b.GetBlock(`^router bgp .*`)
	if err != nil {
		return nil
	}
	var bgp = new(BgpConfig)
	bgp.asNumber = b.parseAS(config)
	bgp.routerID = b.parseRouterID(config)
	bgp.shutdown = strconv.FormatBool(b.parseShutdown(config))
	bgp.networks = b.parseNetworks(config)
	m := b.parseMaxPaths(config)
	bgp.maxPaths = m["maximum_paths"]
	bgp.maxEcmpPaths = m["maximum_ecmp_paths"]
	return bgp
}
func (b *BGPEntity) Neighbors() *BgpNeighborsEntity {
	if b.neighbors == nil {
		b.neighbors = BgpNeighbors(b.AbstractBaseEntity.node)
	}
	return b.neighbors
}
func (b *BGPEntity) parseAS(config string) string {
	re := regexp.MustCompile(`(?m)^router bgp (\d+)`)
	match := re.FindStringSubmatch(config)
	if match == nil {
		return ""
	}
	return match[1]
}
func (b *BGPEntity) parseRouterID(config string) string {
	re := regexp.MustCompile(`(?m)router-id ([^\s]+)`)
	match := re.FindStringSubmatch(config)
	if match == nil {
		return ""
	}
	return match[1]
}
func (b *BGPEntity) parseMaxPaths(config string) map[string]string {
	var maxPaths string
	var maxEcmp string
	re := regexp.MustCompile(`maximum-paths\s+(\d+)(?:\s+ecmp\s+(\d+))?`)
	if match := re.FindStringSubmatch(config); match != nil {
		maxPaths = match[1]
		maxEcmp = match[2]
	}
	return map[string]string{
		"maximum_paths":      maxPaths,
		"maximum_ecmp_paths": maxEcmp,
	}
}
func (b *BGPEntity) parseShutdown(config string) bool {
	matched, _ := regexp.MatchString(`(?m)no shutdown`, config)
	if matched {
		return false
	}
	return !matched
}
func (b *BGPEntity) parseNetworks(config string) []BgpNetworkEntry {
	reNet := regexp.MustCompile(`(?m)network (.+)/(\d+)(?: route-map (\w+))*`)
	matches := reNet.FindAllStringSubmatch(config, -1)
	if matches == nil {
		return nil
	}
	resource := make([]BgpNetworkEntry, len(matches))
	for idx, line := range matches {
		resource[idx] = BgpNetworkEntry{
			"prefix":    line[1],
			"masklen":   line[2],
			"route_map": line[3],
		}
	}
	return resource
}
func (b *BGPEntity) GetSection() string {
	config, err := b.GetBlock(`^router bgp .*`)
	if err != nil {
		return ""
	}
	return config
}
func (b *BGPEntity) ConfigureBgp(cmd string) bool {
	config := b.Get()
	if config == nil {
		return false
	}
	commands := []string{
		"router bgp " + config.BgpAs(),
		cmd,
	}
	return b.Configure(commands...)
}
func (b *BGPEntity) Create(bgpAS int) bool {
	if !(0 < bgpAS && bgpAS < 65535) {
		return false
	}
	cmd := "router bgp " + strconv.Itoa(bgpAS)
	return b.Configure(cmd)
}
func (b *BGPEntity) Delete() bool {
	config := b.Get()
	if config == nil {
		return true
	}
	cmd := "no router bgp " + config.BgpAs()
	return b.Configure(cmd)
}
func (b *BGPEntity) Default() bool {
	config := b.Get()
	if config == nil {
		return true
	}
	cmd := "default router bgp " + config.BgpAs()
	return b.Configure(cmd)
}
func (b *BGPEntity) SetRouterID(value string) bool {
	if value == "" {
		return b.ConfigureBgp("no router-id")
	}
	return b.ConfigureBgp("router-id " + value)
}
func (b *BGPEntity) SetRouterIDDefault() bool {
	return b.ConfigureBgp("default router-id")
}
func (b *BGPEntity) SetMaximumPaths(maxPath int) bool {
	command := "maximum-paths " + strconv.Itoa(maxPath)
	return b.ConfigureBgp(command)
}
func (b *BGPEntity) SetMaximumPathsWithEcmp(maxPath int, maxEcmp int) bool {
	cmd := "maximum-paths " + strconv.Itoa(maxPath) + " ecmp " + strconv.Itoa(maxEcmp)
	return b.ConfigureBgp(cmd)
}
func (b *BGPEntity) SetMaximumPathsDefault() bool {
	return b.ConfigureBgp("default maximum-paths")
}
func (b *BGPEntity) SetShutdown(enable bool) bool {
	cmd := b.CommandBuilder("shutdown", "", false, enable)
	return b.ConfigureBgp(cmd)
}
func (b *BGPEntity) SetShutdownDefault() bool {
	return b.ConfigureBgp("default shutdown")
}
func (b *BGPEntity) AddNetworkWithRouteMap(prefix string, maskLen string, routeMap string) bool {
	command := "network " + prefix + "/" + maskLen
	if routeMap != "" {
		command = command + " route-map " + routeMap
	}
	return b.ConfigureBgp(command)
}
func (b *BGPEntity) AddNetwork(prefix string, maskLen string) bool {
	return b.AddNetworkWithRouteMap(prefix, maskLen, "")
}
func (b *BGPEntity) RemoveNetworkWithRouteMap(prefix string, maskLen string, routeMap string) bool {
	command := "no network " + prefix + "/" + maskLen
	if routeMap != "" {
		command = command + " route-map " + routeMap
	}
	return b.ConfigureBgp(command)
}
func (b *BGPEntity) RemoveNetwork(prefix string, maskLen string) bool {
	return b.RemoveNetworkWithRouteMap(prefix, maskLen, "")
}
type BgpNeighborConfig map[string]string
type BgpNeighborCollection map[string]BgpNeighborConfig
type BgpNeighborsEntity struct {
	*AbstractBaseEntity
}
func BgpNeighbors(node *goeapi.Node) *BgpNeighborsEntity {
	return &BgpNeighborsEntity{&AbstractBaseEntity{node}}
}
func (b *BgpNeighborsEntity) Get(name string) BgpNeighborConfig {
	config, _ := b.GetBlock(`^router bgp .*`)
	return BgpNeighborConfig{
		"peer_group":     b.parsePeerGroup(config, name),
		"remote_as":      b.parseRemoteAS(config, name),
		"send_community": strconv.FormatBool(b.parseSendCommunity(config, name)),
		"shutdown":       strconv.FormatBool(b.parseShutdown(config, name)),
		"description":    b.parseDescription(config, name),
		"next_hop_self":  strconv.FormatBool(b.parseNextHopSelf(config, name)),
		"route_in_map":   b.parseRouteMapIn(config, name),
		"route_out_map":  b.parseRouteMapOut(config, name),
	}
}
func (b *BgpNeighborsEntity) GetAll() BgpNeighborCollection {
	config, _ := b.GetBlock(`^router bgp .*`)
	if config == "" {
		return nil
	}
	re := regexp.MustCompile(`(?m)^\s+neighbor ([^\s]+)`)
	neighbors := re.FindAllStringSubmatch(config, -1)
	hash := map[string]struct{}{}
	collection := make(BgpNeighborCollection)
	for _, matchedLine := range neighbors {
		neighbor := matchedLine[1]
		if _, found := hash[neighbor]; !found {
			hash[neighbor] = struct{}{}
			collection[neighbor] = b.Get(neighbor)
		}
	}
	return collection
}
func (b *BgpNeighborsEntity) parsePeerGroup(config string, name string) string {
	regex := `neighbor ` + name + ` peer-group ([^\s]+)`
	re := regexp.MustCompile(regex)
	match := re.FindStringSubmatch(config)
	if match == nil {
		return ""
	}
	return match[1]
}
func (b *BgpNeighborsEntity) parseRemoteAS(config string, name string) string {
	regex := `neighbor ` + name + ` remote-as (\d+)`
	re := regexp.MustCompile(regex)
	match := re.FindStringSubmatch(config)
	if match == nil {
		return ""
	}
	return match[1]
}
func (b *BgpNeighborsEntity) parseSendCommunity(config string, name string) bool {
	regex := "neighbor " + name + " send-community"
	matched, _ := regexp.MatchString(regex, config)
	return matched
}
func (b *BgpNeighborsEntity) parseShutdown(config string, name string) bool {
	regex := "no neighbor " + name + " shutdown"
	matched, _ := regexp.MatchString(regex, config)
	return !matched
}
func (b *BgpNeighborsEntity) parseDescription(config string, name string) string {
	regex := `(?m)neighbor ` + name + ` description (.*)$`
	re := regexp.MustCompile(regex)
	match := re.FindStringSubmatch(config)
	if match == nil {
		return ""
	}
	return match[1]
}
func (b *BgpNeighborsEntity) parseNextHopSelf(config string, name string) bool {
	regex := "neighbor " + name + " next-hop-self"
	matched, _ := regexp.MatchString(regex, config)
	return matched
}
func (b *BgpNeighborsEntity) parseRouteMapIn(config string, name string) string {
	regex := `(?m)neighbor ` + name + ` route-map ([^\s]+) in`
	re := regexp.MustCompile(regex)
	match := re.FindStringSubmatch(config)
	if match == nil {
		return ""
	}
	return match[1]
}
func (b *BgpNeighborsEntity) parseRouteMapOut(config string, name string) string {
	regex := `(?m)neighbor ` + name + ` route-map ([^\s]+) out`
	re := regexp.MustCompile(regex)
	match := re.FindStringSubmatch(config)
	if match == nil {
		return ""
	}
	return match[1]
}
func (b *BgpNeighborsEntity) Create(name string) bool {
	return b.SetShutdown(name, true)
}
func (b *BgpNeighborsEntity) Delete(name string) bool {
	resp := b.Configure("no neighbor " + name)
	if !resp {
		resp = b.Configure("no neighbor " + name + " peer-group")
	}
	return resp
}
func (b *BgpNeighborsEntity) Configure(cmd string) bool {
	config, _ := b.GetBlock(`^router bgp .*`)
	re := regexp.MustCompile(`(?m)^router bgp (\d+)`)
	match := re.FindStringSubmatch(config)
	if match == nil {
		return false
	}
	commands := []string{
		"router bgp " + match[1],
		cmd,
	}
	return b.AbstractBaseEntity.Configure(commands...)
}
func (b *BgpNeighborsEntity) CommandBuilder(name string, cmd string,
	value string, def bool, shut bool) string {
	str := "neighbor " + name + " " + cmd
	return b.AbstractBaseEntity.CommandBuilder(str, value, def, shut)
}
func (b *BgpNeighborsEntity) SetPeerGroup(name string, value string) bool {
	if net.ParseIP(name) == nil {
		return false
	}
	cmd := b.CommandBuilder(name, "peer-group", value, false, true)
	return b.Configure(cmd)
}
func (b *BgpNeighborsEntity) SetPeerGroupDefault(name string) bool {
	if net.ParseIP(name) == nil {
		return false
	}
	cmd := b.CommandBuilder(name, "peer-group", "", true, false)
	return b.Configure(cmd)
}
func (b *BgpNeighborsEntity) SetRemoteAS(name string, value string) bool {
	cmd := b.CommandBuilder(name, "remote-as", value, false, true)
	return b.Configure(cmd)
}
func (b *BgpNeighborsEntity) SetRemoteASDefault(name string) bool {
	cmd := b.CommandBuilder(name, "remote-as", "", true, false)
	return b.Configure(cmd)
}
func (b *BgpNeighborsEntity) SetShutdown(name string, shut bool) bool {
	cmd := b.CommandBuilder(name, "shutdown", "", false, shut)
	return b.Configure(cmd)
}
func (b *BgpNeighborsEntity) SetShutdownDefault(name string) bool {
	cmd := b.CommandBuilder(name, "shutdown", "", true, false)
	return b.Configure(cmd)
}
func (b *BgpNeighborsEntity) SetSendCommunity(name string, enable bool) bool {
	cmd := b.CommandBuilder(name, "send-community", "", false, enable)
	return b.Configure(cmd)
}
func (b *BgpNeighborsEntity) SetSendCommunityDefault(name string) bool {
	cmd := b.CommandBuilder(name, "send-community", "", true, false)
	return b.Configure(cmd)
}
func (b *BgpNeighborsEntity) SetNextHopSelf(name string, enabled bool) bool {
	cmd := b.CommandBuilder(name, "next-hop-self", "", false, enabled)
	return b.Configure(cmd)
}
func (b *BgpNeighborsEntity) SetNextHopSelfDefault(name string) bool {
	cmd := b.CommandBuilder(name, "next-hop-self", "", true, false)
	return b.Configure(cmd)
}