def test_ClippedPpaByCensus(self):
    # Configuring for -96dBm circle above 40km
    wf_hybrid.CalcHybridPropagationLoss = testutils.FakePropagationPredictor(
        dist_type='REAL', factor=1.0, offset=(96+30-0.1) - 45.0)
    expected_ppa = sgeo.Polygon([(-80.3, 30.3), (-80.7, 30.3),
                                 (-80.7, 30.7), (-80.3, 30.7)])

    ppa_zone = ppa.PpaCreationModel(TestPpa.devices, TestPpa.pal_records)
    ppa_zone = json.loads(ppa_zone)

    self.assertAlmostSamePolygon(
        utils.ToShapely(ppa_zone), expected_ppa, 0.001)
Beispiel #2
0
  def test_ClippedPpaByCensusWithSmallHoles(self):
    # Configuring for -96dBm circle above 40km
    wf_hybrid.CalcHybridPropagationLoss = testutils.FakePropagationPredictor(
        dist_type='REAL', factor=1.0, offset=(96+30-0.1) - 45.0)

    ppa_zone = ppa.PpaCreationModel(TestPpa.devices[1:], TestPpa.pal_records[1:])
    ppa_zone = json.loads(ppa_zone)

    census_zone = utils.ToShapely(
        drive.census_tract_driver.GetCensusTract('06027000100')
        ['features'][0]['geometry'])
    self.assertTrue(utils.ToShapely(ppa_zone).buffer(-1e-6).within(census_zone))
  def test_SimplePpaCircle(self):
    # Configuring for -96dBm circle at 16km includes
    wf_hybrid.CalcHybridPropagationLoss = testutils.FakePropagationPredictor(
        dist_type='REAL', factor=1.0, offset=(96+30-0.1) - 16.0)
    expected_ppa = sgeo.Polygon(
        [vincenty.GeodesicPoint(
            TestPpa.devices[0]['installationParam']['latitude'],
            TestPpa.devices[0]['installationParam']['longitude'],
            dist_km=16.0, bearing=angle)[1::-1]  # reverse to lng,lat
         for angle in xrange(360)])

    ppa_zone = ppa.PpaCreationModel(TestPpa.devices, TestPpa.pal_records)
    ppa_zone = json.loads(ppa_zone)

    self.assertAlmostSamePolygon(
        utils.ToShapely(ppa_zone), expected_ppa, 0.001)
    def test_WINNF_FT_S_PCR_2(self, config_filename):
        """Successful Maximum PPA Boundary Creation Clipped by Service Area Boundary.

    Checks the maximum PPA boundary, being clipped by the Service Area composed of
    one or more adjacent Census Tracts.
    Checks PPA generated by SAS UUT shall be fully contained within the service area.
    """
        # Load the Config file.
        config = loadConfig(config_filename)

        # Register devices and  check response.
        cbsd_ids = self.assertRegistered(config['registrationRequests'],
                                         config['conditionalRegistrationData'])

        # Asserts the REG-Conditional value doesn't exist in the registrationRequest,
        # it is required to be exist in the registrationRequest data.
        assertRegConditionalsForPpaRefModel(
            config['registrationRequests'],
            config['conditionalRegistrationData'])

        # Trigger PPA creation to calculate maximum PPA boundary and check if any errors
        # encountered in PPA creation reference model.
        test_harness_ppa_geometry = ppa.PpaCreationModel(
            config['registrationRequests'], config['palRecords'])

        # Inject the PAL records.
        for pal_record in config['palRecords']:
            self._sas_admin.InjectPalDatabaseRecord(pal_record)

        # Prepares the PAL Ids to trigger ppa creation request.
        pal_ids = [record['palId'] for record in config['palRecords']]
        ppa_creation_request = {"cbsdIds": cbsd_ids, "palIds": pal_ids}

        # Trigger PPA Creation to SAS UUT.
        ppa_id = self.triggerPpaCreationAndWaitUntilComplete(
            ppa_creation_request)
        logging.debug('ppa_id received from SAS UUT:%s', ppa_id)

        # Trigger Full Activity Dump and retrieves the PPA Zone record.
        uut_ppa_zone_data = self.triggerFadGenerationAndRetrievePpaZone(
            ssl_cert=config['sasTestHarnessCert'],
            ssl_key=config['sasTestHarnessKey'])

        # Check if the PPA generated by the SAS UUT is fully contained within the service area.
        logging.debug(
            "SAS UUT PPA - retrieved through FAD:%s",
            json.dumps(uut_ppa_zone_data,
                       indent=2,
                       sort_keys=False,
                       separators=(',', ': ')))
        logging.debug(
            "Reference model PPA - retrieved through PpaCreationModel:%s",
            json.dumps(json.loads(test_harness_ppa_geometry),
                       indent=2,
                       sort_keys=False,
                       separators=(',', ': ')))

        uut_ppa_geometry = uut_ppa_zone_data['zone']['features'][0]['geometry']
        self.assertTrue(isPpaWithinServiceArea(config['palRecords'],
                                               uut_ppa_geometry),
                        msg="PPA Zone is not within service area")

        # Check the Equation 8.3.1 in Test Specfification is satisified w.r t
        # [n.12, R2-PAL-05]. Check the area of the non-overlapping difference between
        # the maximum PPA boundary created by SAS UUT shall be no more than 10% of the area
        # of the maximum PPA boundary created by the Reference Model.
        self.assertTrue(
            utils.PolygonsAlmostEqual(test_harness_ppa_geometry,
                                      uut_ppa_geometry))
    def test_WINNF_FT_S_PCR_1(self, config_filename):
        """Successful Maximum PPA Creation.

    Checks PPA generated by SAS UUT shall be fully contained within the service area.
    """
        # Load the Config file
        config = loadConfig(config_filename)
        # Very light checking of the config file.
        self.assertValidConfig(
            config, {
                'registrationRequests': list,
                'conditionalRegistrationData': list,
                'palRecords': list,
                'sasTestHarnessCert': basestring,
                'sasTestHarnessKey': basestring
            })

        # Register devices and  check response.
        cbsd_ids = self.assertRegistered(config['registrationRequests'],
                                         config['conditionalRegistrationData'])

        # Asserts the REG-Conditional value doesn't exist in the registrationRequest,
        # it required to be exist in the registrationRequest data.
        assertRegConditionalsForPpaRefModel(
            config['registrationRequests'],
            config['conditionalRegistrationData'])

        # Trigger PPA creation to calculate maximum PPA boundary and check if any errors
        # encountered in PPA creation reference model.
        test_harness_ppa_geometry = ppa.PpaCreationModel(
            config['registrationRequests'], config['palRecords'])

        # Inject the PAL records.
        for pal_record in config['palRecords']:
            self._sas_admin.InjectPalDatabaseRecord(pal_record)

        # Trigger SAS UUT to create a PPA boundary.
        pal_ids = [record['palId'] for record in config['palRecords']]
        ppa_creation_request = {"cbsdIds": cbsd_ids, "palIds": pal_ids}

        # Trigger PPA Creation to SAS UUT.
        ppa_id = self.triggerPpaCreationAndWaitUntilComplete(
            ppa_creation_request)
        logging.debug('ppa_id received from SAS UUT:%s', ppa_id)

        # Notify SAS UUT about SAS Harness and trigger Full Activity Dump and
        # retrieves the PPA Zone record.
        uut_ppa_zone_data = self.triggerFadGenerationAndRetrievePpaZone(
            ssl_cert=config['sasTestHarnessCert'],
            ssl_key=config['sasTestHarnessKey'])

        # Write SAS UUT PPA to output directory of PCR.1 test.
        # PPA Zone received from SAS UUT in PCR.1 test will be considered as input
        # for PCR 3,PCR 6 and PCR 7 tests.
        ppa_zone_data_file_path = getSasUutClaimedPpaBoundaryFilePath(
            config_filename.split('/')[-1])
        ppa_zone_data_dir_path = os.path.dirname(ppa_zone_data_file_path)
        if not os.path.exists(ppa_zone_data_dir_path):
            os.makedirs(ppa_zone_data_dir_path)
        with open(ppa_zone_data_file_path, 'w') as file_handle:
            file_handle.write(
                json.dumps(uut_ppa_zone_data['zone'],
                           indent=2,
                           sort_keys=False,
                           separators=(',', ': ')))

        # Check if the PPA generated by the SAS UUT is fully contained within the
        # service area.
        logging.debug(
            "SAS UUT PPA - retrieved through FAD:%s",
            json.dumps(uut_ppa_zone_data,
                       indent=2,
                       sort_keys=False,
                       separators=(',', ': ')))
        logging.debug(
            "Reference model PPA - retrieved through PpaCreationModel:%s",
            json.dumps(json.loads(test_harness_ppa_geometry),
                       indent=2,
                       sort_keys=False,
                       separators=(',', ': ')))

        uut_ppa_geometry = uut_ppa_zone_data['zone']['features'][0]['geometry']
        self.assertTrue(isPpaWithinServiceArea(config['palRecords'],
                                               uut_ppa_geometry),
                        msg="PPA Zone is not within service area")

        # Check the Equation 8.3.1 in Test Specfification is satisified w.r t
        # [n.12, R2-PAL-05]. Check the area of the non-overlapping difference between
        # the maximum PPA boundary created by SAS UUT shall be no more than 10% of the area
        # of the maximum PPA boundary created by the Reference Model.
        self.assertTrue(
            utils.PolygonsAlmostEqual(test_harness_ppa_geometry,
                                      uut_ppa_geometry))
from reference_models.geo import drive
from reference_models.ppa import ppa

# Configuration
user_id = 'pal_user_id_0'
pal_record_filenames = ['pal_record_0.json']
device_filenames = ['device_a.json']
pal_low_frequency = 3550000000
pal_high_frequency = 3650000000
TEST_DIR = os.path.join(os.path.dirname(__file__), 'test_data')

# Change the Default Census Tract Driver Directory to parent directory of test_data
drive.ConfigureCensusTractDriver(TEST_DIR)

# Load Devices and PAL Records
devices = [
    json.load(open(os.path.join(TEST_DIR, device_filename)))
    for device_filename in device_filenames
]
pal_records = [
    json.load(open(os.path.join(TEST_DIR, pal_record_filename)))
    for pal_record_filename in pal_record_filenames
]

# Modify PAL Record to comply with WINNF-TS-0245
pal_records = util.makePalRecordsConsistent(pal_records, pal_low_frequency,
                                            pal_high_frequency, user_id)

ppa = ppa.PpaCreationModel(devices, pal_records)
print ppa