protected LinkedHashMap<Network, List<? extends NicProfile>> configurePublicNic(
      final RouterDeploymentDefinition routerDeploymentDefinition, final boolean hasGuestNic) {
    final LinkedHashMap<Network, List<? extends NicProfile>> publicConfig =
        new LinkedHashMap<Network, List<? extends NicProfile>>(3);

    if (routerDeploymentDefinition.isPublicNetwork()) {
      s_logger.debug("Adding nic for Virtual Router in Public network ");
      // if source nat service is supported by the network, get the source
      // nat ip address
      final NicProfile defaultNic = new NicProfile();
      defaultNic.setDefaultNic(true);
      final PublicIp sourceNatIp = routerDeploymentDefinition.getSourceNatIP();
      defaultNic.setIPv4Address(sourceNatIp.getAddress().addr());
      defaultNic.setIPv4Gateway(sourceNatIp.getGateway());
      defaultNic.setIPv4Netmask(sourceNatIp.getNetmask());
      defaultNic.setMacAddress(sourceNatIp.getMacAddress());
      // get broadcast from public network
      final Network pubNet = _networkDao.findById(sourceNatIp.getNetworkId());
      if (pubNet.getBroadcastDomainType() == BroadcastDomainType.Vxlan) {
        defaultNic.setBroadcastType(BroadcastDomainType.Vxlan);
        defaultNic.setBroadcastUri(BroadcastDomainType.Vxlan.toUri(sourceNatIp.getVlanTag()));
        defaultNic.setIsolationUri(BroadcastDomainType.Vxlan.toUri(sourceNatIp.getVlanTag()));
      } else {
        defaultNic.setBroadcastType(BroadcastDomainType.Vlan);
        defaultNic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(sourceNatIp.getVlanTag()));
        defaultNic.setIsolationUri(IsolationType.Vlan.toUri(sourceNatIp.getVlanTag()));
      }

      // If guest nic has already been added we will have 2 devices in the list.
      if (hasGuestNic) {
        defaultNic.setDeviceId(2);
      }

      final NetworkOffering publicOffering =
          _networkModel
              .getSystemAccountNetworkOfferings(NetworkOffering.SystemPublicNetwork)
              .get(0);
      final List<? extends Network> publicNetworks =
          _networkMgr.setupNetwork(
              s_systemAccount,
              publicOffering,
              routerDeploymentDefinition.getPlan(),
              null,
              null,
              false);
      final String publicIp = defaultNic.getIPv4Address();
      // We want to use the identical MAC address for RvR on public
      // interface if possible
      final NicVO peerNic =
          _nicDao.findByIp4AddressAndNetworkId(publicIp, publicNetworks.get(0).getId());
      if (peerNic != null) {
        s_logger.info("Use same MAC as previous RvR, the MAC is " + peerNic.getMacAddress());
        defaultNic.setMacAddress(peerNic.getMacAddress());
      }
      publicConfig.put(publicNetworks.get(0), new ArrayList<NicProfile>(Arrays.asList(defaultNic)));
    }

    return publicConfig;
  }
  protected void getIp(
      NicProfile nic,
      DataCenter dc,
      VirtualMachineProfile<? extends VirtualMachine> vm,
      Network network)
      throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException,
          ConcurrentOperationException {
    if (nic.getIp4Address() == null) {
      PublicIp ip =
          _networkMgr.assignPublicIpAddress(
              dc.getId(),
              vm.getOwner(),
              dc.getNetworkType().equals(NetworkType.Basic)
                  ? VlanType.DirectAttached
                  : VlanType.VirtualNetwork,
              null);
      nic.setIp4Address(ip.getAddress().toString());
      nic.setGateway(ip.getGateway());
      nic.setNetmask(ip.getNetmask());
      if (ip.getVlanTag() != null && ip.getVlanTag().equalsIgnoreCase("untagged")) {
        nic.setIsolationUri(URI.create("vlan://untagged"));
        nic.setBroadcastUri(URI.create("vlan://untagged"));
        nic.setBroadcastType(BroadcastDomainType.Native);
      } else if (ip.getVlanTag() != null) {
        nic.setIsolationUri(IsolationType.Vlan.toUri(ip.getVlanTag()));
        nic.setBroadcastUri(IsolationType.Vlan.toUri(ip.getVlanTag()));
        nic.setBroadcastType(BroadcastDomainType.Vlan);
      }

      nic.setFormat(AddressFormat.Ip4);
      nic.setReservationId(String.valueOf(ip.getVlanTag()));
      nic.setMacAddress(ip.getMacAddress());
    }
    nic.setDns1(dc.getDns1());
    nic.setDns2(dc.getDns2());
  }