// AddPortMapping adds a port mapping to the specified IGD service.
557780
func (s *IGDService) AddPortMapping(protocol nat.Protocol, internalPort, externalPort int, description string, duration time.Duration) (int, error) {
	tpl := `<u:AddPortMapping xmlns:u="%s">
	<NewRemoteHost></NewRemoteHost>
	<NewExternalPort>%d</NewExternalPort>
	<NewProtocol>%s</NewProtocol>
	<NewInternalPort>%d</NewInternalPort>
	<NewInternalClient>%s</NewInternalClient>
	<NewEnabled>1</NewEnabled>
	<NewPortMappingDescription>%s</NewPortMappingDescription>
	<NewLeaseDuration>%d</NewLeaseDuration>
	</u:AddPortMapping>`
	body := fmt.Sprintf(tpl, s.URN, externalPort, protocol, internalPort, s.LocalIP, description, duration/time.Second)

	response, err := soapRequest(s.URL, s.URN, "AddPortMapping", body)
	if err != nil && duration > 0 {
		// Try to repair error code 725 - OnlyPermanentLeasesSupported
		envelope := &soapErrorResponse{}
		if unmarshalErr := xml.Unmarshal(response, envelope); unmarshalErr != nil {
			return externalPort, unmarshalErr
		}
		if envelope.ErrorCode == 725 {
			return s.AddPortMapping(protocol, internalPort, externalPort, description, 0)
		}
	}

	return externalPort, err
}
1315525
func NewPortMapping(proto, from, to string) (*PortMapping, error) {
	if proto == "" {
		proto = "tcp"
	}
	if proto != "tcp" && proto != "udp" {
		return nil, fmt.Errorf("unsupported protocol %s", proto)
	}
	f, err := NewPortRange(from)
	if err != nil {
		return nil, err
	}
	t, err := NewPortRange(to)
	if err != nil {
		return nil, err
	}
	return &PortMapping{
		Protocol:  proto,
		ToPorts:   t,
		FromPorts: f,
	}, nil
}
796308
func (docker *Docker) ExposePort(portMapping PortMapping) *Docker {
	if docker.PortMappings == nil {
		docker.EmptyPortMappings()
	}

	portMappings := *docker.PortMappings
	portMappings = append(portMappings, portMapping)
	docker.PortMappings = &portMappings

	return docker
}
70766
func (s *GuestOSService) NewAddGuestOsMappingParams(hypervisor string, hypervisorversion string, osnameforhypervisor string) *AddGuestOsMappingParams {
	p := &AddGuestOsMappingParams{}
	p.p = make(map[string]interface{})
	p.p["hypervisor"] = hypervisor
	p.p["hypervisorversion"] = hypervisorversion
	p.p["osnameforhypervisor"] = osnameforhypervisor
	return p
}
664559
func (s *ServerRPC) PortMappingDel(ctx context.Context, req *types.PortMappingModifyRequest) (*types.PortMappingModifyResponse, error) {
	p, ok := s.daemon.PodList.Get(req.PodID)
	if !ok {
		return nil, fmt.Errorf("Pod not found")
	}

	err := p.RemovePortMappingByDest(req.PortMappings)
	if err != nil {
		return nil, fmt.Errorf("p.RemovePortMappingByDest error: %v", err)
	}

	return &types.PortMappingModifyResponse{}, nil
}
435568
func (p *ProxyLB) AddBindPort(mode string, port int) {
	p.Settings.ProxyLB.AddBindPort(mode, port)
}
809021
func OperatePortMap(action Action, chain string, rule []string) error {
	if output, err := Raw(append([]string{
		"-t", string(Nat), string(action), chain}, rule...)...); err != nil {
		return fmt.Errorf("Unable to setup network port map: %s", err)
	} else if len(output) != 0 {
		return &ChainError{Chain: chain, Output: output}
	}

	return nil
}
491284
func MakePortMappings(container *v1.Container) (ports []PortMapping) {
	names := make(map[string]struct{})
	for _, p := range container.Ports {
		pm := PortMapping{
			HostPort:      int(p.HostPort),
			ContainerPort: int(p.ContainerPort),
			Protocol:      p.Protocol,
			HostIP:        p.HostIP,
		}

		// We need to create some default port name if it's not specified, since
		// this is necessary for rkt.
		// http://issue.k8s.io/7710
		if p.Name == "" {
			pm.Name = fmt.Sprintf("%s-%s:%d", container.Name, p.Protocol, p.ContainerPort)
		} else {
			pm.Name = fmt.Sprintf("%s-%s", container.Name, p.Name)
		}

		// Protect against exposing the same protocol-port more than once in a container.
		if _, ok := names[pm.Name]; ok {
			klog.Warningf("Port name conflicted, %q is defined more than once", pm.Name)
			continue
		}
		ports = append(ports, pm)
		names[pm.Name] = struct{}{}
	}
	return
}
993400
func addLocalAddress(addrMgr *addrmgr.AddrManager, addr string, services wire.ServiceFlag) error {
	host, portStr, err := net.SplitHostPort(addr)
	if err != nil {
		return err
	}
	port, err := strconv.ParseUint(portStr, 10, 16)
	if err != nil {
		return err
	}

	if ip := net.ParseIP(host); ip != nil && ip.IsUnspecified() {
		// If bound to unspecified address, advertise all local interfaces
		addrs, err := net.InterfaceAddrs()
		if err != nil {
			return err
		}

		for _, addr := range addrs {
			ifaceIP, _, err := net.ParseCIDR(addr.String())
			if err != nil {
				continue
			}

			// If bound to 0.0.0.0, do not add IPv6 interfaces and if bound to
			// ::, do not add IPv4 interfaces.
			if (ip.To4() == nil) != (ifaceIP.To4() == nil) {
				continue
			}

			netAddr := wire.NewNetAddressIPPort(ifaceIP, uint16(port), services)
			addrMgr.AddLocalAddress(netAddr, addrmgr.BoundPrio)
		}
	} else {
		netAddr, err := addrMgr.HostToNetAddress(host, uint16(port), services)
		if err != nil {
			return err
		}

		addrMgr.AddLocalAddress(netAddr, addrmgr.BoundPrio)
	}

	return nil
}
497557
func (proxier *Proxier) addServiceOnPortInternal(service proxy.ServicePortName, protocol v1.Protocol, proxyPort int, timeout time.Duration) (*ServiceInfo, error) {
	sock, err := proxier.makeProxySocket(protocol, proxier.listenIP, proxyPort)
	if err != nil {
		return nil, err
	}
	_, portStr, err := net.SplitHostPort(sock.Addr().String())
	if err != nil {
		sock.Close()
		return nil, err
	}
	portNum, err := strconv.Atoi(portStr)
	if err != nil {
		sock.Close()
		return nil, err
	}
	si := &ServiceInfo{
		Timeout:             timeout,
		ActiveClients:       newClientCache(),
		isAliveAtomic:       1,
		proxyPort:           portNum,
		protocol:            protocol,
		socket:              sock,
		sessionAffinityType: v1.ServiceAffinityNone, // default
	}
	proxier.serviceMap[service] = si

	klog.V(2).Infof("Proxying for service %q on %s port %d", service, protocol, portNum)
	go func(service proxy.ServicePortName, proxier *Proxier) {
		defer runtime.HandleCrash()
		atomic.AddInt32(&proxier.numProxyLoops, 1)
		sock.ProxyLoop(service, si, proxier.loadBalancer)
		atomic.AddInt32(&proxier.numProxyLoops, -1)
	}(service, proxier)

	return si, nil
}
1197372
func (vrsConnection *VRSConnection) AddPortToAlubr0(intfName string, entityInfo EntityInfo) error {

	namedPortUUID := "port"
	namedIntfUUID := "intf"
	var err error

	// 1) Insert a row for Nuage port in OVSDB Interface table
	extIDMap := make(map[string]string)
	intfOp := libovsdb.Operation{}
	intf := make(map[string]interface{})
	intf["name"] = intfName
	extIDMap["vm-name"] = entityInfo.Name
	extIDMap["vm-uuid"] = entityInfo.UUID
	intf["external_ids"], err = libovsdb.NewOvsMap(extIDMap)
	if err != nil {
		return err
	}
	// interface table ops
	intfOp = libovsdb.Operation{
		Op:       "insert",
		Table:    interfaceTable,
		Row:      intf,
		UUIDName: namedIntfUUID,
	}

	// 2) Insert a row for Nuage port in OVSDB Port table
	portOp := libovsdb.Operation{}
	port := make(map[string]interface{})
	port["name"] = intfName
	port["interfaces"] = libovsdb.UUID{namedIntfUUID}
	port["external_ids"], err = libovsdb.NewOvsMap(extIDMap)
	if err != nil {
		return err
	}
	portOp = libovsdb.Operation{
		Op:       "insert",
		Table:    portTable,
		Row:      port,
		UUIDName: namedPortUUID,
	}

	// 3) Mutate the Ports column of the row in the Bridge table with new Nuage port
	mutateUUID := []libovsdb.UUID{libovsdb.UUID{namedPortUUID}}
	mutateSet, _ := libovsdb.NewOvsSet(mutateUUID)
	mutation := libovsdb.NewMutation("ports", "insert", mutateSet)
	condition := libovsdb.NewCondition("name", "==", bridgeName)
	mutateOp := libovsdb.Operation{
		Op:        "mutate",
		Table:     bridgeTable,
		Mutations: []interface{}{mutation},
		Where:     []interface{}{condition},
	}

	operations := []libovsdb.Operation{intfOp, portOp, mutateOp}
	reply, err := vrsConnection.ovsdbClient.Transact(OvsDBName, operations...)
	if err != nil || len(reply) < len(operations) {
		return fmt.Errorf("Problem mutating row in the OVSDB Bridge table for alubr0")
	}

	return nil
}
528848
func (s *Server) AddPublicEndpointPort(request *PublicEndpointRequest, reply *servicedefinition.Port) error {
	port, err := s.f.AddPublicEndpointPort(s.context(), request.Serviceid, request.EndpointName, request.Name,
		request.UseTLS, request.Protocol, request.IsEnabled, request.Restart)
	if err != nil {
		return err
	}
	*reply = *port
	return err
}
1304992
func (s *ProxyLBSetting) AddBindPort(mode string, port int) {
	var isExist bool
	for i := range s.BindPorts {
		if s.BindPorts[i].ProxyMode == mode && s.BindPorts[i].Port == port {
			isExist = true
		}
	}

	if !isExist {
		s.BindPorts = append(s.BindPorts, &ProxyLBBindPorts{
			ProxyMode: mode,
			Port:      port,
		})
	}
}
304547
func (s *Server) EnableSinglePort() {
	s.singlePort = true
	s.handlers = make(map[string]chan []byte, datagramLength)
	s.gcCollect = make(chan string)
	s.bufPool = sync.Pool{
		New: func() interface{} {
			return make([]byte, datagramLength)
		},
	}
	go s.internalGC()
}
1307928
func (vrsConnection *VRSConnection) AddEntityPort(uuid string, portName string) error {
	var ports []string
	var err error
	if ports, err = vrsConnection.GetEntityPorts(uuid); err != nil {
		return fmt.Errorf("Unable to get existing ports %s %s", uuid, err)
	}

	ports = append(ports, portName)
	row := make(map[string]interface{})
	row[ovsdb.NuageVMTableColumnPorts], err = libovsdb.NewOvsSet(ports)
	if err != nil {
		return err
	}

	condition := []string{ovsdb.NuageVMTableColumnVMUUID, "==", uuid}

	if err = vrsConnection.vmTable.UpdateRow(vrsConnection.ovsdbClient, row, condition); err != nil {
		return fmt.Errorf("Unable to add port %s %s %s", uuid, portName, err)
	}

	return nil
}
501050
func (ce *ContainerEndpoints) AddImport(cancel <-chan struct{}, application string, bind zkservice.ImportBinding) {
	logger := plog.WithFields(log.Fields{
		"application":     application,
		"applicationglob": bind.Application,
		"purpose":         bind.Purpose,
	})
	logger.Debug("Tracking exports for endpoint")
	defer logger.Debug("Exited export tracking for endpoint")
	bind.Application = application

	for {
		select {
		case conn := <-zzk.Connect("/", zzk.GetLocalConnection):
			if conn != nil {

				logger.Debug("Received coordinator connection")

				ch := registry.TrackExports(cancel, conn, ce.opts.TenantID, application)
				for exports := range ch {
					ce.UpdateRemoteExports(bind, exports)
				}

				select {
				case <-cancel:
					return
				default:
				}
			}
		case <-cancel:
			return
		}
	}
}
1118888
func (im *IndexMappingImpl) AddDocumentMapping(doctype string, dm *DocumentMapping) {
	im.TypeMapping[doctype] = dm
}