/**
   * Parses interfaces data from message and puts in into routerModel.
   *
   * @param routerModel to store parsed data
   * @param message to parse interfaces data from
   * @return routerModel updated with interfaces information from message.
   * @throws IOException
   * @throws SAXException
   */
  private System parseInterfaces(System routerModel, String message)
      throws IOException, SAXException {

    // TODO implements a better method to merge the elements in model
    // now are deleted all the existing elements the parser creates
    // before adding new ones (calling the parser)
    routerModel.removeAllLogicalDeviceByType(EthernetPort.class);
    routerModel.removeAllLogicalDeviceByType(LogicalTunnelPort.class);
    routerModel.removeAllHostedServicesByType(GRETunnelService.class);

    IPInterfaceParser ipInterfaceParser = new IPInterfaceParser(routerModel);
    ipInterfaceParser.init();
    ipInterfaceParser.configurableParse(new ByteArrayInputStream(message.getBytes()));

    routerModel = ipInterfaceParser.getModel();
    return routerModel;
  }
  /**
   * Parses logical routers data from message and puts it into routerModel.
   *
   * @param routerModel to store parsed data
   * @param message to parse logical routers data from
   * @return routerModel updated with logical routers information from message.
   * @throws IOException
   * @throws SAXException
   */
  private System parseLRs(System routerModel, String message) throws IOException, SAXException {

    // remove LR from the model before parsing new configuration
    routerModel.removeAllremoveManagedSystemElementByType(ComputerSystem.class);

    DigesterEngine listLogicalRoutersParser = new ListLogicalRoutersParser();
    listLogicalRoutersParser.init();
    listLogicalRoutersParser.configurableParse(new ByteArrayInputStream(message.getBytes()));

    // put new LR in the model
    for (String key : listLogicalRoutersParser.getMapElements().keySet()) {
      ComputerSystem system = new ComputerSystem();
      system.setName((String) listLogicalRoutersParser.getMapElements().get(key));
      routerModel.addManagedSystemElement(system);
    }

    return routerModel;
  }
  private System removeOSPFServiceFromModel(System routerModel) {
    // get OSPFService
    OSPFService ospfService = null;
    for (Service service : routerModel.getHostedService()) {
      if (service instanceof OSPFService) ospfService = (OSPFService) service;
    }
    if (ospfService == null) return routerModel;

    // REMOVE ALL MODEL RELATED TO OSPF
    for (OSPFAreaConfiguration areaConf : ospfService.getOSPFAreaConfiguration()) {
      for (OSPFProtocolEndpointBase ospfPEP : areaConf.getOSPFArea().getEndpointsInArea()) {
        for (LogicalPort port : ospfPEP.getLogicalPorts()) {
          // unlink OSPFProtocolEndpoint with NetworkPorts.
          ospfPEP.removeLogicalPort(port);
        }
        areaConf.getOSPFArea().removeEndpointInArea(ospfPEP);
      }
      ospfService.removeOSPFAreaConfiguration(areaConf);
    }
    routerModel.removeHostedService(ospfService);
    return routerModel;
  }
  private System parseVlans(System routerModel, String message)
      throws UnsupportedEncodingException, IOException, SAXException {

    routerModel.removeAllHostedCollectionByType(BridgeDomain.class);

    VLANParser vlanParser = new VLANParser(routerModel);

    vlanParser.init();
    vlanParser.configurableParse(new ByteArrayInputStream(message.getBytes("UTF-8")));

    routerModel = vlanParser.getModel();

    return routerModel;
  }
  /**
   * Parses routing options data from message and puts in into routerModel.
   *
   * @param routerModel to store parsed data
   * @param message to parse interfaces data from
   * @return routerModel updated with routing options information from message.
   * @throws IOException
   * @throws SAXException
   */
  private System parseRoutingOptions(
      org.opennaas.extensions.router.model.System routerModel, String message)
      throws IOException, SAXException {

    // static routes have to be removed first
    routerModel.removeAllNextHopRoutes();

    RoutingOptionsParser routingOptionsParser = new RoutingOptionsParser(routerModel);
    routingOptionsParser.init();
    routingOptionsParser.configurableParse(new ByteArrayInputStream(message.getBytes("UTF-8")));

    routerModel = routingOptionsParser.getModel();
    return routerModel;
  }