Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.drivers.microsemi.yang; |
| 17 | |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 18 | import org.onlab.packet.VlanId; |
| 19 | import org.onosproject.incubator.net.l2monitoring.cfm.DefaultComponent; |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 20 | import org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceAssociation; |
| 21 | import org.onosproject.incubator.net.l2monitoring.cfm.DefaultMaintenanceDomain; |
| 22 | import org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceAssociation; |
| 23 | import org.onosproject.incubator.net.l2monitoring.cfm.MaintenanceDomain; |
| 24 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdCharStr; |
| 25 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId; |
| 26 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdCharStr; |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 27 | import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId; |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 28 | import org.onosproject.incubator.net.l2monitoring.cfm.impl.CfmMdManager; |
| 29 | import static org.easymock.EasyMock.*; |
| 30 | import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException; |
| 31 | import org.onosproject.incubator.net.l2monitoring.cfm.service.MdStore; |
| 32 | |
| 33 | import java.util.Optional; |
| 34 | |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 35 | /** |
| 36 | * Supports testing of services that reply on the CfmMdService. |
| 37 | */ |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 38 | public class MockCfmMdService extends CfmMdManager { |
| 39 | |
| 40 | @Override |
| 41 | public void activate() { |
| 42 | store = createMock(MdStore.class); |
| 43 | |
| 44 | try { |
| 45 | MaintenanceAssociation ma = DefaultMaintenanceAssociation |
| 46 | .builder(MaIdCharStr.asMaId("ma-1-1"), 6) |
| 47 | .maNumericId((short) 1) |
| 48 | .ccmInterval(MaintenanceAssociation.CcmInterval.INTERVAL_3MS) |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 49 | .addToRemoteMepIdList(MepId.valueOf((short) 10)) |
| 50 | .addToRemoteMepIdList(MepId.valueOf((short) 20)) |
| 51 | .addToComponentList( |
| 52 | DefaultComponent.builder(1) |
| 53 | .addToVidList(VlanId.vlanId((short) 101)).build()) |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 54 | .build(); |
| 55 | |
| 56 | MdId md1Name = MdIdCharStr.asMdId("md-1"); |
| 57 | MaintenanceDomain md1 = DefaultMaintenanceDomain |
| 58 | .builder(md1Name) |
| 59 | .mdNumericId((short) 1) |
| 60 | .mdLevel(MaintenanceDomain.MdLevel.LEVEL3) |
| 61 | .addToMaList(ma) |
| 62 | .build(); |
| 63 | |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 64 | MdId md2Name = MdIdCharStr.asMdId("md-2"); |
| 65 | MaintenanceDomain md2 = DefaultMaintenanceDomain |
| 66 | .builder(md1Name) |
| 67 | .mdNumericId((short) 2) |
| 68 | .mdLevel(MaintenanceDomain.MdLevel.LEVEL2) |
| 69 | .build(); |
| 70 | |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 71 | expect(store.createUpdateMaintenanceDomain(md1)) |
| 72 | .andReturn(true); |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 73 | expect(store.createUpdateMaintenanceDomain(md2)) |
| 74 | .andReturn(true); |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 75 | expect(store.getMaintenanceDomain(md1Name)) |
| 76 | .andReturn(Optional.of(md1)).anyTimes(); |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 77 | expect(store.getMaintenanceDomain(md2Name)) |
| 78 | .andReturn(Optional.of(md2)).anyTimes(); |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 79 | replay(store); |
| 80 | |
| 81 | } catch (CfmConfigException e) { |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 82 | throw new IllegalArgumentException("Error creating MDs for test", e); |
Sean Condon | 0e89bda | 2017-03-21 14:23:19 +0000 | [diff] [blame] | 83 | } |
| 84 | } |
| 85 | } |